C# Relational Operators

Relational Operators are used in a program to check the relationship between two operands and accordingly, it returns boolean values, true or false. These operators are used with loops and Decision-Making Statements during condition checking.

List of relational operators in C#:

OperatorNameExample
==Equal to.A == B
!=Not equal.A != B
>Greater than.A > B
<Less than.A < B
>=Greater than or equal to.A >= B
<=Less than or equal to.A <= B

Example of Relational Operators in C#

using System;

namespace Operators
{
   class Relational
   {
      static void Main(string[] args)
      {
         int a = 11;
         int b = 10;

        	//Gives true and false value
         Console.WriteLine("'==' operator: {0}", a == b);
         Console.WriteLine("'<' operator: {0}", a < b);
         Console.WriteLine("'>' operator: {0}", a> b);
         Console.WriteLine("'!=' operator: {0}", a != b);

         /*Now if we change the value*/
         a = 5;
         b = 20;
         Console.WriteLine("'<=' operator: {0}", a <= b);
         Console.WriteLine("'>=' operator: {0}", a>= b);
      }
   }
}

Output:

'==' operator: False
'<' operator: False
'>' operator: True
'!=' operator: True
'<=' operator: True
'>=' operator: False