In -depth understanding of i and i
The computing symbols in
C# are used to add numerical variables, but there are subtle but important differences between (prefix increment) and
(suffering from suffix). i
i
The calculation results
(Increase in prefix):
i
(suffering from suffix in the suffix): The value of the increased variable storage, but the original value before returning the incremental increase. i
(prefix increment): The incremental operation occurs before other operations in the same expression.
i
Example i
1, but the value of the expression itself is the original value before the increasing (0). Therefore, is set to 0.
On the other hand, increase1 before calculating the expression. Therefore,
is set to 1.<code class="language-csharp">int currentValue = 0; int result1 = ++currentValue; // result1 = 1 int result2 = currentValue++; // result2 = 0</code>
Precautions currentValue
currentValue
result2
It should be noted that the incremental operator in C# will not directly modify the variable itself during the calculation process. Instead, they create a temporary value to perform increasing operations. Then this temporary value will be assigned to the variable. Therefore, when understanding the behavior of these operators, they must consider their results and side effects at the same time.
The above is the detailed content of What's the Difference Between i and i in C#?. For more information, please follow other related articles on the PHP Chinese website!