Use of Relational operators in C#

 

Relational operators  are used for compare two values. For example we may compare the salary of two persons or the price of the two items and so on.these comparison can be done with the help of relational operators such as

A > B , B < C or C >50

Containing a relational operator is called as relational expression. The value of the relational expression is either true or false for example if A=20 , then

A >10  is true

A < 10 is false

Following list of relational operators are shown below with the description

<Is less than
<=Is less than or equal to
>Is greater than
>=Is greater than or equal to
==Is equal to
!=Is not equal to

 

Example

private void SeeRelationalOperators()
{
int a = 10;
int b = 20;
int c = 10;
MessageBox.Show(“a > b is “ + (a > b));   //False
MessageBox.Show(“a < b is “ + (a < b)); //True
MessageBox.Show(“a <= c is ” + (a <= c)); //True

MessageBox.Show(“a >= b is “ + (a >= b)); //False
MessageBox.Show(“a == c is ” + (a == c)); //True
MessageBox.Show(“a != b is “ + (a != b)); //True
}