Variables
C# 是強型別語言,因此每一個變數和物件都必須有宣告的型別。
Types
C#內建的基礎型別有:
* Boolean Type - true and false
* numeric types
- Integrals
The Size and Range of C# Integral Types
Type | Size (in bits) | Range |
sbyte | 8 | -128 to 127 |
byte | 8 | 0 to 255 |
short | 16 | -32768 to 32767 |
ushort | 16 | 0 to 65535 |
int | 32 | -2147483648 to 2147483647 |
uint | 32 | 0 to 4294967295 |
long | 64 | -9223372036854775808 to 9223372036854775807 |
ulong | 64 | 0 to 18446744073709551615 |
char | 16 | 0 to 65535 |
- Floating Point
- Decimal
The Floating Point and Decimal Types with Size, precision, and Range
Type | Size (in bits) | precision | Range |
float | 32 | 7 digits | 1.5 x 10-45 to 3.4 x 1038 |
double | 64 | 15-16 digits | 5.0 x 10-324 to 1.7 x 10308 |
decimal | 128 | 28-29 decimal places | 1.0 x 10-28 to 7.9 x 1028 |
*String - is a sequence of text characters.
字串物件是不變的,表示一旦建立就無法變更。修改字串會有新字串物件的建立,所以基於效能的考量,必須使用 StringBuilder 類別執行大量的串連或其他所需的字串管理,以後再做更詳細的介紹
C# Character Escape Sequences
Escape Sequence | Meaning |
\' | Single Quote |
\" | Double Quote |
\\ | Backslash |
\0 | Null, not the same as the C# null value |
\a | Bell |
\b | Backspace |
\f | form Feed |
\n | Newline |
\r | Carriage Return |
\t | Horizontal Tab |
\v | Vertical Tab |
Operators
在 C# 中,運算子是條件或符號,需要以一或多個運算式 (稱為運算元) 做為輸入並傳回值。
Operators with their precedence and Associativity
Category (by precedence) | Operator(s) | Associativity |
Primary | x.y f(x) a[x] x++ x-- new typeof default checked unchecked delegate | left |
Unary | + - ! ~ ++x --x (T)x | left |
Multiplicative | * / % | left |
Additive | + - | left |
Shift | << >> | left |
Relational | < > <= >= is as | left |
Equality | == != | right |
Logical AND | & | left |
Logical XOR | ^ | left |
Logical OR | | | left |
Conditional AND | && | left |
Conditional OR | || | left |
Null Coalescing | ?? | left |
Ternary | ?: | right |
Assignment | = *= /= %= += -= <<= >>= &= ^= |= => | right |
沒有留言:
張貼留言