Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 336
Jules Avatar asked Mar 16 '10 15:03

Jules


2 Answers

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

like image 100
Reed Copsey Avatar answered Sep 23 '22 08:09

Reed Copsey


Yes, this is correct. As long as you don't override, reference is the default comparison.

like image 41
Nick Craver Avatar answered Sep 23 '22 08:09

Nick Craver