Operators
Sumaiya Tanjil Khan
Lecturer
Department of CSE
Uttara University
Operators in C#
• Arithmetic
• Assignment
• Comparison
• Logical
C# Arithmetic Operators
Increment
prefix increment
In this method, the operator precedes the operand (e.g., ++a). The
value of operand will be altered before it is used.
int a = 1;
int b = ++a; // b = 2
postfix increment
In this method, the operator follows the operand (e.g., a++). The value
operand will be altered after it is used.
int a = 1;
int b = a++; // b = 1
int c = a; // c = 2
Decrement
prefix decrement
In this method, the operator precedes the operand (e.g., – -a). The value of operand
will be altered before it is used.
int a = 1;
int b = --a; // b = 0
postfix decrement
In this method, the operator follows the operand (e.g., a- -). The value of operand will
be altered after it is used.
int a = 1;
int b = a--; // b = 1
int c = a; // c = 0
C# Assignment Operators
An assignment operator is used for assigning a value to a variable. The
most common assignment operator is =
C# Comparison Operators
Comparison operators are used to compare two values (or variables).
This is important in programming, because it helps us to find answers
and make decisions.
The return value of a comparison is either True or False.
Relational Operators
C# Logical Operators
As with comparison operators, you can also test for True or False values
with logical operators.
Logical operators are used to determine the logic between variables or
values:
Logical Operators
Thank You