Study Notes (17): C # fast entry - increment and decrement operators and multi-variable declaration

Learning immediately: https://edu.csdn.net/course/play/20589/257727?utm_source=blogtoedu

Increment and decrement

1 ++ / - either before or after the variable, are equivalent to x = x ± 1

2. m ++ / - is to use a value, then their + 1 / -1

int m=5,n=3;
int m1 = m++;    // m1=5 , m=6
int n1 = n--;    // n1=3 , n=2;

3. ++ m + 1 is the first, the value of m used

int m=5,n=3;
int m1 = ++m;    // m1=6 , m=6
int n1 = --n;    // n1=2 , n=2;

4. If the unary operators and other expression inside the next, separated by a space between the operator to use, otherwise an error

int km = 8;
Console.WriteLine("km=" +(++km));

5. In the format "variable = expression", the expression to follow the right order is calculated

int var1, var2 = 5, var3 = 6;
var1=var2++ * --var3 + ++var2 * var3--;    //5 * 5 + 7 * 5 = 60

 

Published 34 original articles · won praise 0 · Views 321

Guess you like

Origin blog.csdn.net/u013162262/article/details/104743258