Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is GetHashCode() implemented for Int32?

Tags:

c#

.net

clr

I've been looking all over the place, but I can't find anything. Can anyone shed some light on this?

like image 780
Esteban Araya Avatar asked Oct 08 '10 19:10

Esteban Araya


People also ask

How is GetHashCode implemented?

For example, the implementation of the GetHashCode() method provided by the String class returns identical hash codes for identical string values. Therefore, two String objects return the same hash code if they represent the same string value.

What is GetHashCode used for?

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.

What is the return type of the string GetHashCode () in C #?

GetHashCode() Returns the hash code for this string.

Should I override GetHashCode?

Why is it important to override GetHashCode ? It s important to implement both equals and gethashcode, due to collisions, in particular while using dictionaries. if two object returns same hashcode, they are inserted in the dictionary with chaining. While accessing the item equals method is used.


1 Answers

According to Reflector:

public override int GetHashCode() {     return this; } 

Makes sense, does it?

like image 81
Michael Stum Avatar answered Oct 12 '22 08:10

Michael Stum