referenceequals

Built-in IEqualityComparer<T> that uses ReferenceEquals

Is there a default IEqualityComparer implementation that uses ReferenceEquals? EqualityComparer<T>.Default uses ObjectComparer, which uses object.Equals(). In my case, the objects already implement IEquatable, which I need to ignore and compare by object's reference only. Thanks! ...

How to use Object.GetHashCode() on a type that overrides GetHashCode()

Hi, I have a class A that implements IEquatable<>, using its fields (say, A.b and A.c) for implementing/overriding Equals() and overriding GetHashCode(), and everything works fine, 99% of the time. Class A is part of a hierarchy (class B, C) that all inherit from interface D; they can all be stored together in a dictionary Dictionary, t...

Is the 'Is' VB.NET keyword the same as Object.ReferenceEquals?

Is the Is VB.NET keyword the same as Object.ReferenceEquals? ...

In `equals(T value)`, must T be Object, or can it be like City, etc?

I'm trying to understand the equals() method better. All examples I've seen do something like: public class City { public boolean equals(Object other) { if (other instanceof City && other.getId().equals(this.id)) { return true; } // ... } } Must the method take on Object and not...

Object.Equals is virtual, but Object.operator== does not use it in C#?

I got hit by a strange "asymmetry" in C# that I do not really understand. See the following code: using System; using System.Diagnostics; namespace EqualsExperiment { class Program { static void Main(string[] args) { object apple = "apple"; object orange = string.Format("{0}{1}", "ap", "pl...