Relational operators

As the name suggests, relational operators test or define the relationship between two operands, for example, if the first operand is less than the second one, or greater than or equal to it. These operators are applied to numeric operands.

The following table lists a few Binary operators:

Expression Description
< Defined as less than the operator. Used as X < Y. Returns true if the first operand is less than the second operand.
> Defined as greater than an operator. Used as X > Y. Returns true if the first operand is greater than the second operand.
<= Less than Or Equal To operator. Used as X <= Y.
>= Greater than Or Equal To operator. Used as X >= Y.

 

We will use the same variables we defined in the preceding example to understand these relational operators. Here, we are trying to find out whether firstvalue is less than secondvalue or whether firstvalue is greater than secondvalue:

// '<' Operator
Console.WriteLine(firstvalue < secondvalue);
// output = true

// '>' Operator
Console.WriteLine(firstvalue > secondvalue);
// output = false

// '>=' Operator
Console.WriteLine(secondvalue >= firstvalue);
// output = true

// '<=' Operator
Console.WriteLine(firstvalue <= secondvalue);
// output = true
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.137.213