Equality operators

Equality operators are a type of Binary operator, where 2 operands are required. Because they check for the equality of the operands, these can be termed under relational operators as well.

The following table lists the available equality operators:

Expression Description
== This works for predefined value types. Defined as the equality operator. Used as X == Y. Returns true if the first operand is equal to the second operand.
!= Defined as the inequality operator. Used as X! = Y. Returns true if the operands are not equal.

 

We will use the same variables we created in the preceding examples to try and understand the equality operators. Here, we are trying to check if firstvalue is equal or not equal to secondvalue:

//using variables created earlier.
// '==' Operator
Console.WriteLine(secondvalue == firstvalue); // output = false
// '!=' 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
18.220.124.177