, ... , ++ ++ i? , : -)
... pre-increment post-increment? , ( , ):
(, i + 1), (, i + 1), ( i + 1). , i. : " ?" :
- pre increment
++i: i i - post increment
i++: i i
... , increments i . ( ).
( Lippert . , , , , , , ) ( )
1:
unchecked
{
int i = Int32.MaxValue;
Console.WriteLine("Hello! I'm trying to do my work here {0}", i++);
Console.WriteLine("Work done {1}", i);
}
2:
checked
{
int i = Int32.MaxValue;
Console.WriteLine("Hello! I'm trying to do my work here {0}", i++);
Console.WriteLine("Work done {1}", i);
}
checked , (OverflowException). unchecked , . Int32.MaxValue + 1 . checked , unchecked i -1.
. :
Hello! I'm trying to do my work here 2147483647
Work done -1
... i , Console.WriteLine (Int32.MaxValue == 2147483647). - Console.WriteLine.
. :
System.OverflowException: Arithmetic operation resulted in an overflow.
... , -, , , , Console.WriteLine ( ).
, , , , .
. ? , . Pre post increments C # . ( , ++ !). , , -, , .
"" -
for (int i = 0; i < x; i++)
i++;
""
(nothing)