Hash Code

What Does Hash Code Mean?

Hash code in .NET framework is a numeric value which helps in identification of an object during equality testing and also can serve as an index for the object. The value contained in the hash code is not permanent in nature. The purpose of hash code is to help in efficient lookup and insertion in data collections which are based on a hash table.


Techopedia Explains Hash Code

Two objects are considered equal if they return equal hash codes. However, matching resultant hash codes do not necessarily mean object equality, or in other words, the reverse does not hold true. Because of this reason, hash code should never be used outside the boundaries of the application domain, as the same object could have different values outside the domain, processes or platforms.

As the value in hash code is temporary in nature, it should never be used as a key for data retrieval from a keyed data collection and should never be serialized or stored in databases. The GetHashCode method is used in .NET framework to get the hash code. It is suited for hashing algorithms or for data structures such as hash tables. The value returned by the function could differ between different .NET framework versions. As such, the framework does not approve the default implementation of the method, and so should not be used for finding the unique object identifier in the case of hashing purposes.

Hash code can aid in data comparison tasks. It can also help in one-way encryption, as the generated numeric value cannot be traced back to the original message data.


Related Terms

Latest Software Development Terms

Related Reading

Margaret Rouse

Margaret Rouse is an award-winning technical writer and teacher known for her ability to explain complex technical subjects to a non-technical, business audience. Over the past twenty years her explanations have appeared on TechTarget websites and she's been cited as an authority in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine and Discovery Magazine.Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages. If you have a suggestion for a new definition or how to improve a technical explanation, please email Margaret or contact her…