C#: Operators Cheat Sheet

# Arithmetic Operators

+Adds two operands
-Subtracts second operand from the first
*Multiplies both operands
/Divides numerator by de-numerator
%Modulus Operator and remainder of after an integer division
++Increment operator increases integer value by one
--Decrement operator decreases integer value by one

# Relational Operators

==Checks if the values of two operands are equal or not, if yes then condition becomes true.
!=Checks if the values of two operands are equal or not, if values are not equal then condition becomes true.
>Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true.
<Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true.
>=Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true.
<=Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true.

# Logical Operators

&&Called Logical AND operator. If both the operands are non zero then condition becomes true.
||Called Logical OR Operator. If any of the two operands is non zero then condition becomes true.
!Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.

# Assignment Operators

=Simple assignment operator, Assigns values from right side operands to left side operand
+=Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand
-=Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand
*=Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand
/=Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand
%=Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand
<<=Left shift AND assignment operator
>>=Right shift AND assignment operator
&=Bitwise AND assignment operator
^=bitwise exclusive OR and assignment operator
|=bitwise inclusive OR and assignment operator

# Miscellaneous Operators

sizeof()Returns the size of a data type.
typeof()Returns the type of a class.
&Returns the address of an variable.
*Pointer to a variable.
? :Conditional Expression
isDetermines whether an object is of a certain type.
asCast without raising an exception if the cast fails.

Leave a Reply

Your email address will not be published. Required fields are marked *