I should familiar with this chapter. If not, I should hit the wall.
2.1 A First C# Program
I'm very glad to see the first C# program is not a hello world program. :-)
The first program introduce the variable, method, Main, Class, Namespace.
Nothing important to me, I think.
2.2 Syntax
Identifiers: The name of the class, method, variable, namespace and so on. Start with Unicode character or under score. C# is case-sensitive.
Keywords: The words system choose which can't be an identifier, reserved word. You can use prefix @ to use a keyword as identifier. Then you can use it like "@class". But if you use prefix @ to a common identifier, the "@a" and "a" is the same.
Contextual Keywords: I don't know it exactly, maybe they are recognized as keywords in special area.
Literals: Data in the code.
Punctuators: Separator. E.g. , ; {}
Operators: Transform and combine expressions. E.g. + - * /
Comments: // single line comment /* */ multiline comment
I decide to not note all the things, it is too much to note, oops. I just note the useful information.
2.3 Type Basics
- Predefine types and Custom types
- Value types, Reference types and Pointer types
- Different of value type and reference type
- Memory allocate: value just an object, reference has a reference and an object
- Copy: value copy the object, reference copy the reference means point the same object
- Different of value type and reference type
- Struct is a Custom Value type
2.4 Numeric Types
Numeric Literal inference: I use to think is totally wrong.
If there is a decimal point then the literal is a double , else it is a int or long and so on
Checked and Unchecked operator
Real number rounding error: see some statements
decimal m = 1M / 6M; // 0.1666666666666666666666666667M
double d = 1.0 / 6.0; // 0.16666666666666666
decimal notQuiteWholeM = m+m+m+m+m+m; // 1.0000000000000000000000000002M
double notQuiteWholeD = d+d+d+d+d+d; // 0.99999999999999989
double d = 1.0 / 6.0; // 0.16666666666666666
decimal notQuiteWholeM = m+m+m+m+m+m; // 1.0000000000000000000000000002M
double notQuiteWholeD = d+d+d+d+d+d; // 0.99999999999999989
So don't use float or double to financial calculation, I think.
2.5 Boolean Type and Operators
Bool alias System.Boolean
Bool value can't convert to numeric types
Condition operators(&& || !) short-circuit evaluation when possible, &, | don't do short-circuit evaluation
2.6 Strings and Characters
Escape characters: /u Unicode
@: verbatim string
2.7 Arrays
Declaration:
C#: int[] array = new int[5]; In actually, int[] array is declaration, and new int[5] is initialize
C++: int array[5];
Default initialize: value type 0 or false and so on, reference type is null
Multidimensional array:
rectangular array: int[,] array = new int[3,3];
Jagged Array: int[][] array = new int[3][]; array[0] = new int[4];
Var: I think it will be introduce more in later chapter
2.8 Variables and Parameters
Memory allocate: stock and heap
Stock: local variables and parameters
Heap: New objects
Definite Assignment:
- Local variables must be assigned a value before they can be read.
- Function arguments must be supplied when a method is called.
- All other variables (such as fields and array elements) are automatically initialized by the runtime.
Default Value:
Reference null
Numeric type or Enum type 0
char type '/0'
bool type false
Parameter pass style
None
|
Value
|
Going in
|
Ref
|
Reference
|
Going in
|
Out
|
Reference
|
Going out
|
2.9 Expression and Operators
Operator Precedence
2.10 Statements
Goto in switch
Goto case 12;
2.11 Namespace
Some advantage feature: I don't think it is very import, and I don't know some of them well, NEED TO READ AGAIN