8.7. Relational Operators

Relational operators are used mostly in the condition part of if-else and while constructs.

8.7.1. The == Operator

The equality operator (==) is a binary operator and compares the two operands on each side of the operator for equality. For value types, the == operator returns true if the value of the operands is equal and false otherwise. For reference data types, the == operator returns true if the two references refer to the same object. For string objects, the == operator returns true if the contents of the two strings are equal.

Java programmers should be careful of this feature of C#. In C#, the == operator on strings does what the equals() method of Java strings does. The == operator can be overloaded only if the ...

Get .NET for Java Developers: Migrating to C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.