Получи случайную криптовалюту за регистрацию!

List some different ways for equality check in .NET The Re | C# 1001 notes

List some different ways for equality check in .NET

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.