C# Operators

C# Provide some built in operators. The are
  1. Arithmetic Operators
  2. Relational Operators
  3. Logical Operators
  4. Bitwise Operators
  5. Assignment Operators 
Arithmetic Operators

Arithmetic Operators Explains that Let suppose X=10 , Y=5

OperatorDescriptionExample
+Adds two operandsX + Y = 15
-Subtracts second operand from the firstX - Y = 5
*Multiplies both operandsX * Y = 50
/Divides numerator  by  denominator result should be the  quotientX / Y = 2
%Modulus Operator and remainder of after an integer divisionY % X = 0
++Increment operator increases integer value by oneX++ = 11
--Decrements operator decreases integer value by oneY-- = 9
Relational Operator:

Relational Operators Explains that Let suppose X=10 , Y=5

OperatorDescriptionExample
==It will check the values of two operands are equal or not, If yes then condition becomes true.(X == X) False.
!=It Will check the values of two operands are equal or not, if values are not equal, Then the condition becomes true.(X != Y) True.
>It Will check the value of left operand is greater than the value of right operand, If yes then condition becomes true.(X > Y) True.
<It will checks the value of left operand is less than the value of right operand, If yes then condition becomes true.(X < Y) False.
>=It will checks the value of left operand is greater than or equal to the value of right operand, If yes then condition becomes true.(X >= Y) True.
<=It will check the value of left operand is less than or equal to the value of right operand, If yes then condition becomes true.(X <= Y) False.
Logical Operator:

Logical Operators Explains that Let suppose X=true, Y=false

OperatorDescriptionExample
&&Logical AND operator. If both the operands are true then condition becomes true else false.(X && Y) false.
||Logical OR Operator. If any of the two operands is true then condition becomes true.(X || Y) true.
!Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.!(X && Y) true.
Assignment Operator:

Assignment Operator explains that X, Y and Z

OperatorDescriptionExample
=Simple assignment operator, Assigns values from right side operands to left side operandZ = X + Y assigns value of X + Y into Z
+=Add AND assignment operator, It adds right operand to the left operand and assign the result to left operandZ += X is equivalent to Z = Z + X
-=Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operandZ -= X is equivalent to Z = Z - X
*=Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operandZ *= X is equivalent to Z = Z * X
/=Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operandZ /= X is equivalent to Z = Z / X
%=Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operandZ %= X is equivalent to Z = Z % X
<<=Left shift AND assignment operatorZ <<= 2 is same as Z = Z << 2
>>=Right shift AND assignment operatorZ >>= 2 is same as Z = Z >> 2
&=Bitwise AND assignment operatorZ &= 2 is same as Z = Z & 2
^=bitwise exclusive OR and assignment operatorZ ^= 2 is same as Z = Z ^ 2
|=bitwise inclusive OR and assignment operatorZ |= 2 is same as Z = Z| 2

Popular Posts