Arithmetic operators
+: Two operands added, example: 2+3 of 5
-: The first operand minus the second operand example: 5-3 of 2
*: Two operands multiplied, example: 2*3 of 6
/: Numerator divided by denominator, example: 5/2 to 2
%: modulo operator, remainder after divisible, example: 5%2 1
+ +: increment operator, integer value increased by 1, example: i++
--: Self-decrement operator, integer value reduced by 1, example: i--
Relational operators
= = Check that the values of the two operands are equal and true if they are equal
! =: Checks whether the values of the two operands are equal, or true if they are not equal
Check whether the value of the left operand is greater than the value of the right operand, or true if it is
<: Check if the value of the left operand is less than the value of the right operand, or ture if it is
>=: Checks whether the value of the left operand is greater than or equal to the value of the right operand, or true if it is
<=: Checks whether the value of the left operand is less than or equal to the value of the right operand, or true if it is
logical operators
&&: with operator. True if none of the two operands are nonzero
|| : Or operator. Ture if any of the two operands is nonzero
!: Non-operator. If the condition is true, the non-operator will make it false
Assignment Operators
=: assignment operator, assigning the value of the right operand to the left operand
+ =: Plus and assignment operators, assigning the result of the right operand plus the left operand to the left operand
-=: Minus and assignment operator, assigning the result of the left operand minus the right operand to the left operand
*=: Multiply and assign operator to assign the right operand to the left operand by multiplying the result of the left operand
/=: In addition to and assignment operators, assigns the left operand to the left operand by dividing the result of the right operand by the number of
%=: Modulo and assignment operators, for modulo assignment of two operands to left operand
<<=: Left Shift and assignment operator
&=: Bitwise-and-assignment operators
^=: Bitwise XOR and assignment operators
|=: Bitwise OR and assignment operators
Bitwise operators
&: If it is present in two operands, the binary and operator copies one to the result
|: If it exists in either operand, the binary OR operator copies one to the result
^: If it exists in one of the operands but does not exist in two operands, the binary XOR operator copies one to the result
~: The bitwise inverse operator is a unary operator with a "flip" bit effect, i.e. 0 becomes 1, 1 becomes 0, including the sign bit
<<: Binary left shift operator. Left operand value moves left the number of digits specified by the right operand
>>: Binary right-shift operator. The value of the left operand moves the right operand to the specified number of digits
Bitwise operators"&"is the binocular operator whose function is to participate in the operation of the two number of the corresponding binary and only the corresponding two binary is 1 o'clock, the result bit is 1, otherwise 0 of the number of participating operations in the complement of the example:9&5 9The binary complement is0000 1001 5The binary complement is0000 0101Results0000 0001Then:9&5=1or operator "|"is the binocular operator whose function is to participate in the operation of the two number of the corresponding binary phase or as long as the corresponding two binary has one for 1 o'clock, the result bit is 1 participate in the operation of the two numbers are in the complement example:9|5 0000 1001|0000 0101Results0000 1101Then:9|5= -
Other operators
?:: Conditional operator, which returns one of two values based on the value of a Boolean expression
Format: Condition? First_expression:second_expression;
If the condition is true, the first expression is evaluated and the result of its calculation is the same, and if False, the second expression is evaluated and the result of its calculation prevail. Only one of the two expressions is calculated
?? : What if?? The left operand of the operator is not NULL, the operator returns the left operand, otherwise the right operand is returned
Operator Precedence
Arithmetic operators >> relational operators >> logical operators >> assignment operators
Example
usingSystem;namespacedemo{classProgram {Static voidMain (string[] args) {intA =5; intb; Console.WriteLine (5+5); Console.WriteLine (-a); Console.WriteLine (A-1); Console.WriteLine (5*2); Console.WriteLine (5.0%2.2); Console.WriteLine (A--); Console.WriteLine (--a); Console.WriteLine (true|false); Console.WriteLine (true^false); Console.WriteLine (1.1<1.1); Console.WriteLine ("The value of B is {0}", B = (A = =1) ? -: -); } }}
Results
c#-operator (iv)