Search C # (value type 2) C # talent bird (QQ: 249178521)
4. Connection
· Rule 1
W In addition to the other binary operators outside the assignment operator is left.
X Y Z should be understood as (x y) Z
· Rule 2
W assignment operator and?: The operator is connected to the right.
X = y = z should be understood as x = (y = z)
X = y = Z should be understood as x = (y = z)
A? B: C? D: E should be understood as a? b: (C? D: E)
5. The order of calculation
• The operand is strictly calculated from left to right.
INT m = 2;
INT Answer = M * M M * M;
The order of calculation:
3 * m M * M
3 * 4 M * M
12 M * M
12 5 * M
12 5 * 6
12 30
42
6. Integer overflow
· Spill error
w un / checked (expression)
w un / checked {statement}
INT m = ...
Method (Checked (m * 2));
m = checked (m * 2);
Checked
{
Method (m * 2);
m * = 2;
}
Each statement above is overflow error check
Method (m * 2);
m * = 2;
Each statement above is compiled with CSC / Checked * .cs, overflow error checks
Each statement above is compiled with CSC / Checked- * .cs, not overflow error check
Method (Unchecked (M * 2));
m = unchecked (m * 2);
unchecked
{
Method (m * 2);
m * = 2;
}
Each statement above is not overflow error check
Checked (expression) Checks if an expression is overflow. It can be used for any expression, but only the integer operator can act because only these operators produce overflow. These operators are: , -, - (negative), - (minus), *, /,%, and integer between explicit type conversion. The result of Checked (expression) is also an expression, which can be used as part of another expression:
Int Outcome = Checked (...);
Checked {statement} Checks if a series of statement results overflow. It is not an expression, there is no result. For example, there is a statement below generate an error:
INT nooutcome = checked {...};
(Note: Checked (expression) parentheses is a bracket, while checked {statement} parentheses is a curly bracket).
Unchecked is not checked.