Comparison Operators

C#The operators, which we use with If and Else statement for comparison are known as Comparison Operators. A list of comparison operators is given below with their symbolic representation.

Symbol Meaning
== Equal
!= Not Equal
> Greater Than
< Less Than
>= Greater Than or Equal
<= Less Than or Equal

 

A sample code is given below about the usage of Comparison Operators with If and Else statement.

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int number = 2;

            if (number == 1)
            {
                Console.WriteLine("The number is 1.");
            }
            else if (number >= 1)
            {
                Console.WriteLine("The number is greater than or equal to 1.");
            }
            else
            {
                Console.WriteLine("Unknown number.");
            }
        }
    }
}

Output:

The number is greater than or equal to 1.