C# – Operators

An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. C# has rich set of built – in operators and provide the following type of operators –

  • Arithmetic Operators
  • Relational Operators
  • Logical and Bitwise Operators
  • Assignment Operators
  • Other Operators

Arithmetic Operators

Several common arithmetic operators are allowed in C#.

%Remainder or modulo
++Increment by 1
Decrement by 1

Relational Operators

Relational Operators are used for comparison purpose in conditional statements. Common relational operators in c# are :

==Equality check
!=Un – equality check
>Greater than
<Less than
>=Greater than or equal to
<=Less than or equal to

Relational operators always result in a Boolean statement; either true or false.

Logical and Bitwise Operators

These operators are used for logical and bitwise calculations. Common logical and bitwise operators in C# are:

&Bitwise AND
|Bitwise OR
^Bitwise XOR
!Bitwise NOT
&&“Logical ” or ” short circuit ” AND
||” Logical” or ” short circuit ” OR

The operators &, | and ^ are rarely used in usual programming practice. The NOT operator is used to negate a Boolean or bitwise expression.

Assignment Operators

Assignment Operators are used to assign values to variables. Common assignment operators in C# are :

Operand Description
=Simple assignment
+=Additive assignment
-=subtractive assignment
*=Multiplicative assignment
/=Division assignment
%=Modulo assignment

The equal (=) operator is used to assign value to an object.

Other Operators

There are some other operators present in c#. A short description of these is given below:-

Operand Description
<<Left shift bitwise operator
>>Right shift bitwise operator
.Member access for objects
[]Index operator used in arrays and collections
()Cast operator
?:Ternary operator

Leave a Reply

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