
📝 How can we check equality in .NET?
🔸 The
🔸 The
🔸 The
🔸 The
🔸 The comparison operator
#post
🔸 The
ReferenceEquals()
method - checks if two reference type variables(classes, not structs) are referred to the same memory address.🔸 The
virtual Equals()
method. (System.Object) - checks if two objects are equivalent.🔸 The
static Equals()
method - is used to handle problems when there is a null value in the check.🔸 The
Equals
method from IEquatable interface.🔸 The comparison operator
==
- usually means the same as ReferenceEquals, it checks if two variables point to the same memory address. The gotcha is that this operator can be override to perform other types of checks. In strings, for instance, it checks if two different instances are equivalent.#post