C # has three operators: unary operations, two-dollar operations, and three-dimensional operations. The so-called two-dollar operation is to participate in the operation of the variable has two, the other two analogy.
A Mathematical operations
One dollar includes: +,-,++ and--。
such as: int x=10; int x1=+x;int x2=-x; so x1=10;x2=-10.
These two operations are relatively simple. Binary operation: Add, subtract, multiply, divide, take the remainder, the corresponding symbol is +,-,*,/and%; The first 4 I don't want to say, primary school, basically is: variable 1 = variable 2 (subtraction) variable 3 mode; For example: x=42%10 result x=2, in fact, the remainder operation and mathematical is the principle of modulo is the same, is the first number divided by the second number of remainders. int y=81%9; So y=0, this operation is back in primary school, the method of asking questions here is different.
Plus + + can be merged as two strings in a string. Take a look at the following example:
string str1 = "Hello";
string str2 = "Hello";
string str3 = str1 + str2;
Console.WriteLine ("Str1={0}", str1);
Console.WriteLine ("Str2={0}", str2);
Console.WriteLine ("Str3=str1+str2:{0}", STR3);
Console.readkey (); Other parts of the program have been saved.
Its output results are:
Self-increasing and self-subtraction operations: ++,--
These two operations in the back of the loop has a lot of effect, + + is the role of their own value +1,--is since minus 1. But in the process of assignment operations int a=10;
Then: int b=++a;int c=a++; the result B and C are not equal.
int a = 10;
int a1=a;
int b = ++a;
int c = a++;
Console.WriteLine ("A Original value a1{0}", A1);
Console.WriteLine ("A later value {0}", a);
Console.WriteLine ("B=++a{0}", b);
Console.WriteLine ("C=a++{0}", c);
The result of the output is:
Explanation: In B=++a here, first A is added to B, and a a1=a is used to hold the original value of a.
After that, the value of A=a1;a becomes 10;c=a++, where a first assigns the value to C and then increases by 1.
The same + + operation is also the same. All in all, if + + or--in the front, then it's the first increment or decrement, and then the assignment, if + + and--at the back is first assigned value and then self reduction.
Two Assignment operator symbol
The main operations include: = (Assignment), +=,-=,*=,/=,%=.
Assignment = operation is very simple, the basic is to two types of variables, one of the values assigned to the other.
int x = 0; int y; y = x; the remaining four operating principles are the same, as shown in the following example:
int x1, x2, x3;
x1 = 11; x2 = 12; x3 = x1;
X1 + = x2;//x1=x1+x2;
x2 = x3;//x2=x2-x3; and x2=x2-x1;
Console.WriteLine ("X1 Original value is {0}", x3);
Console.WriteLine ("x1+=x2 x1 value {0}", X1);
Console.WriteLine ("x2-=x1 x2 value {0}", x2);
Console.readkey ();
The result:
Look again *=;
int x1, x2, x3;
x1 = 11; x2 = 33; x3 = x1;
X1 *= x2;//x1=x1*x2;
X2/= x3;//x2=x2/x3; and x2=x2-x1;
Console.WriteLine ("X1 Original value is {0}", x3);
Console.WriteLine ("x1*=x2 x1 value {0}", X1);
Console.WriteLine ("x2/=x1 x2 value {0}", x2);
The result of the output is:
The rest of the results for the reader to do their own programming experience.
One place to note here is: Console.WriteLine ("x1*=x2 x1 value {0}", x1); {0}, which is output using the specified format, see:
Console.WriteLine ("x1 value is {0},x2 value is {1},x3 value is {2}", x1,x2,x3); The result is: