Relational operators in C#

(Last Updated On: January 29, 2019)

Relational operators in C# – Relational operators in C# language e.g. equal, greater than or less than etc. are used to check the relationship between two variables or expressions. It is also known as comparison operators in C# programming.

For example,

If int a =10 and int b =20;
Then, we car write a relation ship as a == b to check if a and b are equal.

Or as , a > = b; to check if a is >= b etc.

NOTE: All Relational operators returns Boolean value. E.g. considering above value of a and b, the expression, a == b, returns false, as a is 10 and b=20.

List of relational operators in C# language.

= = Equal to, e.g. a == b;

> Greater than e.g. a > b;

< Less that e.g. a < b; > = Greater than or equal to. E.g. a >= b;

< = Less than or equal to. E.g. a <=b;

!= Not equal to. E.g. a != b;

 

C# Code:

Uses of all relational operators are shown by C# program example. All expressions using relational operators returns true or false as an output.

Output:
a == b :false
a > b :false
a = b :false
a <= b :true
a != b :true