Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 5
    That documentation quote must have come from a very early version. It is no longer written like this in current MSDN articles, probably because it is quite wrong. Commented Jul 21, 2010 at 18:43
  • 4
    They changed the wording, yes, but it still says basically the same thing: "Consequently, the default implementation of this method must not be used as a unique object identifier for hashing purposes." Commented Jul 21, 2010 at 23:31
  • 9
    Why does the documentation claim that implementation is not particularly useful for hashing? If an object is equal to itself and nothing else, any hash code method which will always return the same value for a given object instance, and will generally return different values for different instances, what's the problem? Commented Jan 4, 2013 at 23:33
  • 4
    @ta.speot.is: If what you want is to determine whether a particular instance has already been added into a dictionary, reference equality is perfect. With strings, as you note, one is usually more interested in whether a string containing the same sequence of characters has already been added. That's why string overrides GetHashCode. On the other hand, suppose you want to keep a count of how many times various controls process Paint events. You could use a Dictionary<Object, int[]> (every int[] stored would hold exactly one item). Commented Apr 25, 2013 at 14:58
  • 6
    @It'sNotALie. Then thank Archive.org for having a copy ;-) Commented Nov 6, 2013 at 22:43