Search code examples
c#.netvb.netdictionaryreference-type

Quick question about a reference type key in a generic dictionary in .Net


I have a mutable class that I'm using as a key to a generic dictionary. Two keys should be equal only if their references are equal. From what I've read, in this case, I don't need to override Equals, GetHashCode , or implement IEqualityComparer.

Is this correct?


Solution

  • Yes. The default comparison operation in System.Object uses reference equality. If this behavior is what you want, the defaults should work fine.