VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-object-gethashcode-method-with-examples/

⇱ C# | Object.GetHashCode() Method with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# | Object.GetHashCode() Method with Examples

Last Updated : 11 Jul, 2025
This method is used to return the hash code for this instance. A hash code is a numeric value which is used to insert and identify an object in a hash-based collection. The GetHashCode method provides this hash code for algorithms that need quick checks of object equality. Syntax:
public virtual int GetHashCode ();
Return Value: This method returns a 32-bit signed integer hash code for the current object. Below programs illustrate the use of Object.GetHashCode() Method: Example 1:
Output:
Type is :System.Object
Hash Code is :37162120
Example 2:
Output:
Author details:
first Name : Kirti
last Name : Mangal
The hash code of object is: -751588944
Important Points:
  • Two objects that return different hash codes means objects are not equal but the reverse is not true. Means, equal hash codes do not imply object equality, because different (unequal) objects can have identical hash codes.
  • The .NET Framework does not guarantee the default implementation of the GetHashCode method, and the value this method returns may differ between .NET Framework versions and platforms, such as 32-bit and 64-bit platforms.
  • A hash code is not a permanent value so do not serialize, store the hash values in databases etc.
  • Do not test for equality of hash codes to determine whether two objects are equal.
Reference: https://learn.microsoft.com/en-us/dotnet/api/system.object.gethashcode?view=netframework-4.7.2
Comment
Article Tags:

Explore