Relational operators are used to compare the values and returns Boolean values, if condition is true – they return True, otherwise they return False.
Here is the list of relation operators,
- "==" (Equal To) – it returns true, if both operand’s values are equal
- "!=" (Not Equal To) – it returns true, if both operand’s values are not equal
- "<" (Less Than) – it returns true if first, operand is less than second operand
- "<=" (Less Than or Equal To) – it returns true, if either first operand is less than or equal to second operand
- ">" (Greater Than) – it returns true, if first operand is greater than second operand
- ">=" (Greater Than or Equal To) – it returns true, if either first operand is greater than or equal to second operand
Syntax:
Operand1 == Operand2
Operand1 != Operand2
Operand1 < Operand2
Operand1 <= Operand2
Operand1 > Operand2
Operand1 >= Operand2
Example:
Input:
int a = 10;
int b = 3;
Console.WriteLine("a==b: {0}", (a == b));
Console.WriteLine("a!=b: {0}", (a != b));
Console.WriteLine("a>b : {0}", (a > b));
Console.WriteLine("a>=b: {0}", (a >= b));
Console.WriteLine("a<b : {0}", (a < b));
Console.WriteLine("a<=b: {0}", (a <= b));
Output:
a==b: False
a!=b: True
a>b : True
a>=b: True
a<b : False
a<=b: False
C# code to demonstrate example of relational operators
Output