Operators are the foundation of any programming language, the program is incomplete without the operators as we use them in all of our programs.

Operators are the symbol that performs a specific mathematical or logical operation on operands.
Example: Addition : 2 + 3, where 2 and 3 are the operands and + is the operator.

Following are the types of Operators in C#.

• Arithmetic Operators
• Assignment Operators
• Relational Operators
• Logical Operators
• Unary Operators
• Bitwise Operators
• Ternary or Conditional Operator
• Miscellaneous Operators

C# Arithmetic Operators

Arithmetic Operators are used to perform mathematical operations on operands such as addition, subtraction, multiplication, division etc.

C# Assignment Operators

These operators are used in a program to assign a value of the right-hand side to the left-hand side as shown below.

You can combine write in short version such as instead of writing, int a = a+5, you can write it as a += 5.

Following are the list of assignment operators used in C#.

C# Relational Operators

These operators are used in a program to check the relationship between two operands and accordingly, it returns boolean values, true or false. These are used with loops and Decision-Making Statements during condition checking.

List of relational operators in C#:

C# Logical Operators

These operators are used to compute the logical operation in a program such as &&|| and !. They are used to evaluate the condition.

The following are the C# Logical Operators. Assume X holds the value 1 and Y holds 0

C# Unary Operators

These operators are the Increment and Decrement Operators. They operate on a single operand. They are ++ and -- operators. ++ is used to increase the value by 1 and — is used to decrease the value by 1.

• Post-Increment or Post-Decrement:
First, the value is used for operation and then incremented or decremented. Represented as a++ or a–.
• Pre-Increment Pre-Decrement:
Here First the value is incremented or decremented then used for the operation. Represented as ++a or –a.

C# Bitwise Operators

Bitwise operators are used to perform a bit-level operation on operands. They are used in testing, setting, or shifting the actual bits in a program.

You can see the truth table below.

Below are the list of Bitwise operators:

C# Ternary or Conditional Operator (?:)

It is a short-hand version of the if-else statement that operates on three operands. The ternary operator (or Conditional operator) returns a true or false after checking the condition.

Syntax of ternary operator:

Explanation:

• condition: It checks the condition for a true or false value.
• expression1: If the condition is true expression1 is evaluated.
• expression2: If the condition is false expression2 is evaluated.

Output:

Miscellaneous Operators

Apart from the above operators, there are various other operators used in C# programming and they are:

Operator Precedence in C#

In a program, there may be an expression that uses more than one operator, in such case operator precedence determines which is to be evaluated first and next.

Let us take an example:

The output of the above expression is 60 because the precedence of multiplication is higher than the addition. So first (5 * 10) is evaluated and then 10 is added to the result.

The following shows the precedence and associativity of C# operators:

Associativity refers to the direction of the operators to be evaluated first and next. It may be right to left or left to right.

Keith Number Program in C

In this tutorial, we will write a Keith number in C. It is one of the most asked questions in an interview. Before that, you …

Keith Number Program in C++

In this tutorial, we will write a Keith number in C++. It is one of the most asked questions in an interview. Before that, you …

In this tutorial, we will write a C++ program to implement singly linked list. In this program, we will create a separate function for each …

Fascinating Number Program in C

In this tutorial, we will write a C program to check whether the given number is a Fascinating number or not. You may go through …

Peterson Number in C

In this tutorial, we will learn about the Peterson number and check if the number is Peterson or not in C. What is Peterson Number? …

Peterson Number in C++

In this tutorial, we will learn about the Peterson number and write a C++ program to check if the given number is a Peterson number …