C# Basic- Operators
By Dhananjay Masal– CODEMIND Technology
Contact us +91 9890217463
1
What are Operators in C#?
- used to perform operations on operands. For example, consider
the expression 2 + 3 = 5, here 2 and 3 are operands, and + and =
are called operators
2
1. Types of Operators in C#:
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Bitwise Operators
5. Assignment Operators
6. Unary Operators or Ternary Operator or Conditional Operator
3
1. Arithmetic Operators
Arithmetic operators are used for performing mathematical calculations.
● Addition (+): Adds two operands.
● Subtraction (-): Subtracts the second operand from the first.
● Multiplication (*): Multiplies two operands.
● Division (/): Divides the first operand by the second.
● Modulus (%): Returns the remainder when the first operand is divided by the
second.
4
2. Comparison Operators
Equal to (==): Checks if two operands are equal.Not equal to (!=): Checks if two operands
are not equal.
Greater than (>): Checks if the first operand is greater than the second.
Less than (<): Checks if the first operand is less than the second.
Greater than or equal to (>=): Checks if the first operand is greater than or equal to the
second.
Less than or equal to (<=): Checks if the first operand is less than or equal to the second.
5
3. Logical Operators
logical operators are used to combine conditional statements.
● Logical AND (&&): True if both operands are true.
● Logical OR (||): True if at least one of the operands is true.
● Logical NOT (!): Inverts the value of the operand.
6
4. Conditional Operator (Ternary Operator)
The conditional operator evaluates a Boolean expression and returns one of two
values depending on whether the expression is true or false.
csharp
7
Operators
1. Unary Operator: The Operator that requires one operand (variable or
value) to perform the operation is called Unary Operator.
2. Binary Operator: Then Operator that requires two operands
(variables or values) to perform the operation is called Binary
Operator.
3. Ternary Operator: The Operator that requires three operands
(variables or values) to perform the operation is called Ternary
Operator. The Ternary Operator is also called Conditional Operator.
8
Operators
9
Thank You
Success is not a milestone, it's a journey. And we have
vowed to help you in yours.
www.codemindtechnology.com
10