Introduction
The operator is a special functionality that is used to manipulate mathematical equations. In C# or any Object-Oriented Programming language, a defined operator is the symbol that is used to perform a mathematical expression or some specific task. The operator always performs between two operands. This campaign aims to solve arithmetic equations.
For example, (a+b)^2, (a-b)^2, A^2 + B^2 + 2AB etc.
There are three types of operators in C#,
- Unary Operator
- Binary Operator
- Tannery operator
Unary Operator
Unary means single or one, which means that when an operation occurs with an operator, that operator is called a unary operator.
Suppose any operation is performed with a single operator that single operator is called a unary operator. A unary operator is used to increment or decrement the original value of a variable.
A single operation is performed with a single operator that single operator is called a unary operator. A unary operator is used to increment or decrement the original value of a variable.
There are two types of unary operators
- Increment
It raises the value of the variable increment operator, which is commonly used in loops. - Pre-increment
To increment first then print the value. - Post-increment
To first print the value then increment. - Decrement
It decries the value of the variable decrement operator, which is commonly used in loops. - Pre-decrement
To decrement the first then print the value. - Post-decrement
To first print the value then decrement.
For example, to determine the working of increment or decrement.
static void Main(string[] args) {
int value1 = 56;
Console.WriteLine("This is Example for Pre and Post Increment Operator");
Console.WriteLine("Original Value: {0} ", value1); //print the original value.
Console.WriteLine("Pre- Increment value: {0} ", ++value1); //First to print the value then increment operator perform.
Console.WriteLine("Post-Increment Value: {0} ", value1++); // First to Increment the value then print the incremented value.
Console.WriteLine("Original Value: {0} ", value1);
Console.WriteLine("***************************************");
Console.WriteLine("This is Example for Pre and Post Decrement Operator");
Console.WriteLine("Original Value: {0} ", value1); //print the original value.
Console.WriteLine("Pre-Decrement value: {0} ", --value1); //First to print the value then decrement operator perform.
Console.WriteLine("Post-Decrement Value: {0} ", value1--); // First to decrement the value then print the decremented value.
Console.WriteLine("Original Value: {0} ", value1);
Console.ReadLine();
}
Output

Binary operator
Binary operators act upon two operands to produce a new value. Such, operators can be classified into different categories these are.
Arithmetic operators
The arithmetic operators are used in solving mathematical equations.
- Addition(+)
The addition operator is used to sum two numbers. For example a+b - Subtraction (-)
The subtraction operator is used to subtract two numbers. For example a-b - Multiplication (*)
The multiplication operator is used to multiply two numbers. For example a*b - Division (/)
The division operator is used to divide two numbers. For example a/b - Modulo (%)
The modulo operator is used to modulo two numbers. For example a%b
Example of Binary operator
static void Main(string[] args) {
int value1 = 55;
int value2 = 25;
Console.WriteLine("This is Example of Binay Operator");
Console.WriteLine("Arithmetic Operation with two operands Value1 = {0}, value2 = {1} ", value1, value2);
Console.WriteLine("Addition of two Number: {0} ", value1 + value2);
Console.WriteLine("Subtraction of two Number: {0} ", value1 - value2);
Console.WriteLine("Multiplication of two Number: {0} ", value1 * value2);
Console.WriteLine("Division of two Number: {0} ", value1 / value2);
Console.WriteLine("Modulo of two Number: {0} ", value1 % value2);
Console.ReadLine();
}
Output






Efthimis KontogourisPosted Jun 2, 2022, 10:13 AM
There are no tannary operators. You mean ternary operators.