Beginning Microsoft® Visual C#® 2008_Chapter_3_Variables and Expressions
Basic C# Syntax
- 一開始程式結構還有註解,跟Java沒啥不一樣,很快過去。
- C#有個特殊註解///,Chapter 31會解釋。
Basic C# Console Application Structure
- 主程式一樣是static void Main(string[] args)
- #region #endregion 程式碼摺疊起來的時候,可以對該區域做一個註解,這註解會顯示在編輯視窗上面。
Variables
- < type > < name > ;
Simple Types
- numbers and Boolean
- the mechanics of storing numbers as a series of 0s and 1s in the memory of a computer
- The u characters before some variable names are shorthand for unsigned
- three floating - point variable types: float , double , and decimal
- The first two store floating points in the form +/ – m × 2e , where the allowed values for m and e differ for each type.
- decimal uses the alternative form +/ – m × 10e .
- three other simple types:
Type | Alias For | Allowed Values |
---|---|---|
sbyte | System.SByte | Integer between – 128 and 127 |
byte | System.Byte | Integer between 0 and 255 |
short | System.Int16 | Integer between – 32768 and 32767 |
ushort | System.UInt16 | Integer between 0 and 65535 |
int | System.Int32 | Integer between – 2147483648 and 2147483647 |
uint | System.UInt32 | Integer between 0 and 4294967295 |
long | System.Int64 | Integer between – 9223372036854775808 and 9223372036854775807 |
ulong | System.UInt64 | Integer between 0 and 18446744073709551615 |
Type | Alias For | Min M | Max M | Min E | Max E | Approx. Min Value | Approx. Max Value |
---|---|---|---|---|---|---|---|
float | System.Single | 0 | 224 | -149 | 104 | 1.5 * 10 -45 | 3.4 * 10 38 |
double | System.Double | 0 | 253 | -1075 | 970 | 5.0 * 10 -324 | 1.7 * 10 308 |
decimal | System.Decimal | 0 | 296 | -26 | 0 | 1.0 * 10 -28 | 7.9 * 10 28 |
Type | Alias For | Allowed Values |
---|---|---|
char | System.Char | Single Unicode character, stored as an integer between 0 and 65535 |
bool | System.Boolean | Boolean value, true or false |
string | System.String | A sequence of characters |
Variable Naming
- basic rules:
- The first character of a variable name must be either a letter, an underscore character ( _ ), or the at symbol ( @ ).
- Subsequent characters may be letters, underscore characters, or numbers
- no keywords
- case sensitive
Naming Conventions
- Hungarian notation: placing a lowercase prefix on all variable names that identify the type
- it is far better to name variables appropriately for their purpose
- two naming conventions are used in the .NET Framework namespaces: PascalCase and camelCase .
- For your simple variables, stick to camelCase. Use PascalCase for certain more advanced naming, which is the Microsoft recommendation.
沒有留言:
張貼留言