SiteMap  | About    

What is HashCode ?

What is Hashing?

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.

.Net interview questions and answers

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.

Object.GetHashCode Method

The GetHashCode() provides hash code for algorithms that need quick checks of object equality.

class HashProgram { static void Main(string[] args) { TestObject obj = new TestObject(); Console.WriteLine(obj.GetHashCode()); Console.ReadLine(); } }

Difference between a.Equals(b) and a == b

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 (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.