OPERATORS IN C#
OPERATORS
• An operator is a symbol that tells the compiler to perform specific
mathematical or logical manipulations.
Operators can be categorized based upon their
different functionality :
• ARITHMETIC OPERATORS
• RELATIONAL OPERATORS
• LOGICAL OPERATORS
• BITWISE OPERATORS
• ASSIGNMENT OPERATORS
OPERATORS CAN ALSO
CATEGORIZED BASED UPON NUMBER OF
OPERANDS :
• Unary Operator
• Binary Operator
• Ternary Operator
ARITHMETIC OPERATORS
Operator OPERATOR NAME
+ ADDITION OPERATOR
- SUBTRATION OPERATOR
* MULTIPLICATIONOPERATOR
/ DIVISION OPERATOR
% MODULUS OPERATOR
++ INCREEMENT OPERATOR
-- DECREEMENT OPERATOR
These are used to perform arithmetic operations on operands.
RELATIONAL OPERATORS
Operator OPERATOR NAME
== EQUAL TO
!= NOT EQUAL TO
> GREATER THAN
< LESS THAN
>= GREATER THAN EQUAL TO
<= LESS THAN EQUAL TO
Relational operators are used for comparison of two values.
LOGICAL OPERATORS
• They are used to combine two or more conditions/constraints or to
complement the evaluation of the original condition in consideration.
Operator OPERATOR NAME Example Result
&& Logical And (5<2)&&(5>3) False
|| Logical Or (5<2)||(5>3) True
! Logical not !(5<2) True
BITWISE OPERATOR
• Bitwise and bit shift operators are used to perform bit level operations on
integer (int, long, etc) and boolean data.
Operator Operator Name Example
~ Bitwise Complement
(~A) =-61 In
11000011
& Bitwise AND
(A&B)=12, In
00001100
| Bitwise OR (A|B)=61, In 00111101
^
Bitwise Exclusive
OR(XOR)
(A^B)=49, In 00110001
<< Bitwise left Shift
A<<2=240, In
11110000
ASSIGNMENT OPERATORS
• Assignment operators are used to assigning a value to a variable. Ex:
int a;
a= 10;OPERATOR Operator Name Example
= Value assign from right side to
left operand
C = A + B assigns value of A + B
into C
+= Add and assign C += A is equivalent to C = C +
A
-= Subtract and assign C -= A is equivalent to C = C -
A
*= Multiply and assign C *= A is equivalent to C = C *
A
/= Devide and assign C /= A is equivalent to C = C /
A
%= Modulus and assign C %= A is equivalent to C = C
% A
OPERATOR Operator Name Example
<<= Left shift AND assignment
operator
C <<= 2 is same as C = C <<
2
>>= Right shift AND assignment
operator
C >>= 2 is same as C = C >>
2
&= Bitwise AND assignment
operator
C &= 2 is same as C = C & 2
^= bitwise exclusive OR and
assignment operator
C ^= 2 is same as C = C ^ 2
|= bitwise inclusive OR and
assignment operator
C |= 2 is same as C = C | 2
THANK YOU

Operators in C#

  • 1.
  • 2.
    OPERATORS • An operatoris a symbol that tells the compiler to perform specific mathematical or logical manipulations. Operators can be categorized based upon their different functionality : • ARITHMETIC OPERATORS • RELATIONAL OPERATORS • LOGICAL OPERATORS • BITWISE OPERATORS • ASSIGNMENT OPERATORS
  • 3.
    OPERATORS CAN ALSO CATEGORIZEDBASED UPON NUMBER OF OPERANDS : • Unary Operator • Binary Operator • Ternary Operator
  • 4.
    ARITHMETIC OPERATORS Operator OPERATORNAME + ADDITION OPERATOR - SUBTRATION OPERATOR * MULTIPLICATIONOPERATOR / DIVISION OPERATOR % MODULUS OPERATOR ++ INCREEMENT OPERATOR -- DECREEMENT OPERATOR These are used to perform arithmetic operations on operands.
  • 5.
    RELATIONAL OPERATORS Operator OPERATORNAME == EQUAL TO != NOT EQUAL TO > GREATER THAN < LESS THAN >= GREATER THAN EQUAL TO <= LESS THAN EQUAL TO Relational operators are used for comparison of two values.
  • 6.
    LOGICAL OPERATORS • Theyare used to combine two or more conditions/constraints or to complement the evaluation of the original condition in consideration. Operator OPERATOR NAME Example Result && Logical And (5<2)&&(5>3) False || Logical Or (5<2)||(5>3) True ! Logical not !(5<2) True
  • 7.
    BITWISE OPERATOR • Bitwiseand bit shift operators are used to perform bit level operations on integer (int, long, etc) and boolean data. Operator Operator Name Example ~ Bitwise Complement (~A) =-61 In 11000011 & Bitwise AND (A&B)=12, In 00001100 | Bitwise OR (A|B)=61, In 00111101 ^ Bitwise Exclusive OR(XOR) (A^B)=49, In 00110001 << Bitwise left Shift A<<2=240, In 11110000
  • 8.
    ASSIGNMENT OPERATORS • Assignmentoperators are used to assigning a value to a variable. Ex: int a; a= 10;OPERATOR Operator Name Example = Value assign from right side to left operand C = A + B assigns value of A + B into C += Add and assign C += A is equivalent to C = C + A -= Subtract and assign C -= A is equivalent to C = C - A *= Multiply and assign C *= A is equivalent to C = C * A /= Devide and assign C /= A is equivalent to C = C / A %= Modulus and assign C %= A is equivalent to C = C % A
  • 9.
    OPERATOR Operator NameExample <<= Left shift AND assignment operator C <<= 2 is same as C = C << 2 >>= Right shift AND assignment operator C >>= 2 is same as C = C >> 2 &= Bitwise AND assignment operator C &= 2 is same as C = C & 2 ^= bitwise exclusive OR and assignment operator C ^= 2 is same as C = C ^ 2 |= bitwise inclusive OR and assignment operator C |= 2 is same as C = C | 2
  • 10.