Click here to Skip to main content
Click here to Skip to main content
Alternatives (2)

Tagged as

Using GetHashCode correctly

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

Alternatives

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
Qwertie
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...

License

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

Share

About the Author

Rossl321
Web Developer
Australia Australia
No Biography provided

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