C# Comparison Operators

In this chapter you will learn:

  • What is C# Comparison Operator?
  • How many types of Comparison Operators in C sharp?
  • How to use Comparison operators in a program?

The C# comparison operator is used to compare two operands. It returns true or false based on comparison. The complete list of comparison operators are listed in a table.

Consider x is a variable and the value assigned the x=2 then,

<Less thanx<5 (returns true)
>Greater thanx>5 (returns false)
<=Less than equal tox<=2 (returns true)
>=Greater than equal tox>=2 (returns true)
==Equal equal tox==2 (returns true)
!=Not equal tox!=2 (returns false)
  • Examples:


    Enter first number         4
    Enter second number    6
    6 is greater than 4

    You will learn more about if…else constructs in lateral session.


    In this chapter, you learned about different types of C# comparison operatorsand also learned how to use it in a program. In next chapter, you will learn about  Logical Operators in C#.

    Leave a Reply

    Your email address will not be published. Required fields are marked *