In order for the = operator to work as the assignment operator, the only thing that can be to the left of it is the variable you're assigning a value to. This can be its declaration or an existing instance. The left operand must be an l-value.
This compares the two operands based on the rules below:
true if the references are for the same object and false
otherwise.
- If the operands both implement IEquatable, it returns the return value from "
leftOperand.equals rightOperand
".
- Otherwise, for primitive types only, it returns
true
if the bits stored in both instances match and false
if they don't.
If the type is a structure that doesn't implement IEquatable, it should fail to compile. If you need to compare instances of a reference type, consider using IEquatable or IComparable. If one operand is a reference type and the other is a by value type, the compiler will attempt to use IEquatable on the value type. If that fails, it should fail to compile.