An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.
There are Four types of operators listed below :
1. Arithmetic Operators
example subtraction :
int x = 10;
int y = 4;
Console.WriteLine(x-y);
// outputs 6
example division :
Division
the division operator ( / ) divides the first operand by the second. If the operands are both integers, any remainder is dropped in order to return an integer value.
int x = 10 / 4;
Console.WriteLine(x);
// outputs 2
division by 0 is undefined and will crash your program.
example modulus :
Modulus
the modulus operator ( % ) is informally known as the remainder operator because it returns the remainder of an integer division.
int x = 25 % 7 ;
Console.WriteLine( x );
// outputs 4
example Prefix & poarfix forms :
a. The increment operator has two forms, prefix and postfix.
++x; // prefix
x++; // postfix
prefix increaments the value and then proceeds with the expression.
postfix evaluates the expression and then performs the incrementing.
prefix example :
int x = 3;
int y = ++x;
// x is 4, y is 4
postfix example :
int x = 3;
int y = x++;
// x is 4, y is 3
The prefix example increments the value of x and then assigns it to y.
The postfix example assigns the value of x to y and then increments x.
b. The Decrement operator
The decrement operator ( -- ) works in much the same way as the increment operator but instead of increasing the value , it decreases it by one.
--x; // prefix
x--; // postfix
2. Relational Operator
Use relational operators to evaluate conditions. in addition to the less than ( < ) and greater than ( > ) operator, the following operators are available :
example :
if (a == b)
{
Console.WriteLine("equal");
}
// Display equal if the value of a is equal to the value of b
3. Logical Operator
4. Assignment Operators
Next : C# series 1.2 : Variables
There are Four types of operators listed below :
1. Arithmetic Operators
example subtraction :
int x = 10;
int y = 4;
Console.WriteLine(x-y);
// outputs 6
example division :
Division
the division operator ( / ) divides the first operand by the second. If the operands are both integers, any remainder is dropped in order to return an integer value.
int x = 10 / 4;
Console.WriteLine(x);
// outputs 2
division by 0 is undefined and will crash your program.
example modulus :
Modulus
the modulus operator ( % ) is informally known as the remainder operator because it returns the remainder of an integer division.
int x = 25 % 7 ;
Console.WriteLine( x );
// outputs 4
example Prefix & poarfix forms :
a. The increment operator has two forms, prefix and postfix.
++x; // prefix
x++; // postfix
prefix increaments the value and then proceeds with the expression.
postfix evaluates the expression and then performs the incrementing.
prefix example :
int x = 3;
int y = ++x;
// x is 4, y is 4
postfix example :
int x = 3;
int y = x++;
// x is 4, y is 3
The prefix example increments the value of x and then assigns it to y.
The postfix example assigns the value of x to y and then increments x.
b. The Decrement operator
The decrement operator ( -- ) works in much the same way as the increment operator but instead of increasing the value , it decreases it by one.
--x; // prefix
x--; // postfix
2. Relational Operator
Use relational operators to evaluate conditions. in addition to the less than ( < ) and greater than ( > ) operator, the following operators are available :
example :
if (a == b)
{
Console.WriteLine("equal");
}
// Display equal if the value of a is equal to the value of b
3. Logical Operator
4. Assignment Operators
Next : C# series 1.2 : Variables
No comments:
Post a Comment