What is HashCode ?
A hash code is a numeric value that is used to identify an object during equality testing. To address the issue of integrity, it is common to make use of hash codes. The goal is for every object to return a distinct hash code, but this often cannot be absolutely guaranteed. That is, the default implementation of the GetHashCode() method does not guarantee unique return values for different objects.
If two objects are equal(object1.equals(object2))then these two objects return same hash code. For ex: the System.String class has overridden this method to return a different hash value for the current character data. Thus, if you have two identical strings, System.String.GetHashCode will return the same value. The only thing that the Hash Code should obey is that equal objects have equal Hash Code. However, the reverse is not true. Equal hash codes do not imply object equality, because different objects can have identical hash codes.
The GetHashCode() provides hash code for algorithms that need quick checks of object equality.
Difference between a.Equals(b) and a == b
The Equals() and == operator are used for comparison and both returns the Boolean value (true/false). More about.... a.Equals(b) and a == b
- Can you store multiple data types in an Array
- Is string a value type or a reference type
- Difference between parse and tryparse
- What are the type of Errors
- What is anonymous type ?
- Difference between Singleton and a Static Class
- Difference between Properties and Fields
- What does the [Flags] Enum Attribute Mean?