C# OPERATORS
Operators are used
to perform operations on variables and values.
OPERATOR:
-is a symbol
which performs an operation on the given operands.
OPERAND:
-is a value
on which an operator performs an operation.
Operators in any programming language are broadly categorized into,
Unary Operators: accept only One operand.
Binary Operators: accept two operands.
Ternary Operators: accept three operands.
TYPES OF OPERATORS: LARA BICS
L-->Logical
Operators
A-->
Arithmetic Operators
R-->Relational Operators
A-->Assignment Operators
B-->Bitwise
Operators
I-->Increment and Decrement Operators
C-->Conditional Operators
S--> Special
Operators
LOGICAL OPERATOR:
Logical operators are used to determine the logic between variables or values:
|
Operator |
Name |
Description |
Example |
|
&& |
Logical And |
Returns true if both statement are true |
x<y&&x<y |
|
| | |
Logical Or |
Returns true if one of the statements is true |
x<y||x<y |
|
! |
Logical Not |
Revers the result, returns false if the result is true |
!(x<y&&x<y) |
EXAMPLE:
OUTPUT:ARITHMETIC OPERATOR:
Arithmetic operators are
used to perform common mathematical operations:
|
Operators |
Name |
Description |
Example |
|
+ |
Addition |
Add together
two values |
x+y |
|
- |
Subtraction |
Subtract one
value from another |
x-y |
|
* |
Multiplication |
Multiple two
values |
x*y |
|
/ |
Division |
Divided one
value by another values |
x/y |
|
% |
Modulus |
Returns the
division remainder |
x%y |
EXAMPLE:
RELATIONAL OPERATOR:
Relational Operators are also
known as Comparison Operators.
|
Operators |
Name |
Description |
Example |
|
= |
Equal to |
Check if the
values of two operands equal or not, if yes then condition becomes true. |
(5==10) is
not true. |
|
!= |
Not equal |
Check if the
values of two operands equal or not, if values are not equal then condition
becomes true. |
(5!=10) is
true. |
|
> |
Greater then |
Check if the
values of left operand is greater than the value of left operand , if yes then condition become true. |
(5>10) is
not true. |
|
< |
Less then |
Check if the
values of Right operand is less than the value of right operand, if yes then condition become true. |
(5<10) is true. |
|
>= |
Greater then
or equal to |
Check if the
values of left operands is greater
than or equal to the value of right operand, if yes then condition become
true. |
(5>=10)is
not true |
|
<= |
Less then or
equal to |
Check if the
values of right operand is less than or equal to the value of left operand, if
yes then condition become true. |
(5<=10)is
true. |
ASSIGNMENT OPERATOR:
Assignment Operators is used to assign a values to variables.
We use the
assignment operator(=) to assign the value.
|
Operators |
Syntax |
|
= |
a=4 |
|
+= |
a+=4 |
|
-= |
a-=4 |
|
*= |
a*=4 |
|
/= |
a/=4 |
|
%= |
a%=4 |
|
&= |
a&=4 |
|
|= |
a|=4 |
|
^= |
a^=4 |
|
>>= |
a>>=4 |
|
<<= |
a<<=4 |
OUTPUT:
TERNARY OPERATOR:
C# includes a decision making operator ?: which is called the conditional operator or ternary operator.
It is the short form of the if else conditions.
SYNTAX:
condition ? statement 1:statement2
The ternary operator starts with a Boolean Condition. It this with a Boolean condition. It this condition evaluates to true then it will execute the first statement after ? otherwise second statement after : will be executed.
EXAMPLE:
OUTPUT:









