Click here to Skip to main content
12,695,538 members (27,212 online)
Click here to Skip to main content
Alternatives (2)
Add your own
alternative version

Tagged as


2 bookmarked

Using GetHashCode correctly

, 3 Oct 2011 CPOL
It may not always be obvious what makes a good source for a HashCode.


Members may post updates or alternatives to this current article in order to show different approaches or add new features.

16 Oct 2011
Panos Rontogiannis
For reference types, the hash is based on an internal counter that is incremented every time a descendant of System.Object is created. This happens in System.Object's constructor.For value types (structs), the hash is based on the first field. So if the first field is immutable, then you don't...
12 Oct 2011
Assuming you are writing a class (not a struct), you can basically get a fixed random hashcode simply by NOT overriding GetHashCode() but inheriting the implementation from System.Object. Unfortunately the System.Object implementation is not documented in the standard .NET documentation[^] but I...


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Australia Australia
No Biography provided

| | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 3 Oct 2011
Article Copyright 2011 by Rossl321
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid