tagged [gethashcode]

Do I need to override GetHashCode() on reference types?

Do I need to override GetHashCode() on reference types? I read most questions on StackOverflow with regards to `GetHashCode`. But I am still not sure whether I have to override `GetHashCode` on refere...

15 Dec at 00:57

Seeding a pseudo-random number generator in C#

Seeding a pseudo-random number generator in C# I need a seed for an instance of C#'s `Random` class, and I read that most people use the current time's ticks counter for this. But that is a 64-bit val...

30 Oct at 23:28

What's the role of GetHashCode in the IEqualityComparer<T> in .NET?

What's the role of GetHashCode in the IEqualityComparer in .NET? I'm trying to understand the role of the GetHashCode method of the interface IEqualityComparer. The following example is taken from MSD...

How are Equals and GetHashCode implemented on anonymous types?

How are Equals and GetHashCode implemented on anonymous types? The Help says this: > Anonymous types are class types that derive directly from object, and that cannot be cast to any type except objec...

25 Jul at 02:11

C# how to calculate hashcode from an object reference

C# how to calculate hashcode from an object reference Folks, here's a thorny problem for you! A part of the TickZoom system must collect instances of every type of object into a Dictionary type. It is...

31 May at 16:28

Persistent hashcode for strings

Persistent hashcode for strings I want to generate an integer hashcode for strings, that will stay constant forever; i.e. the same string should always result in the same hashcode. The hash does not h...

25 Apr at 15:53

GetHashCode() problem using xor

GetHashCode() problem using xor My understanding is that you're typically supposed to use xor with GetHashCode() to produce an int to identify your data by its value (as opposed to by its reference). ...

20 Jun at 09:12

Correct way to override Equals() and GetHashCode()

Correct way to override Equals() and GetHashCode() I have never really done this before so i was hoping that someone could show me the correct what of implementing a override of Except() and GetHashCo...

28 Feb at 14:37

GetHashCode and Equals are implemented incorrectly in System.Attribute?

GetHashCode and Equals are implemented incorrectly in System.Attribute? Seeing from [Artech's blog](http://www.cnblogs.com/artech/archive/2012/01/12/attribute-gethashcode.html) and then we had a discu...

12 Jan at 17:26

.NET unique object identifier

.NET unique object identifier Is there a way of getting a unique identifier of an instance? `GetHashCode()` is the same for the two references pointing to the same instance. However, two different ins...

23 May at 12:2

General advice and guidelines on how to properly override object.GetHashCode()

General advice and guidelines on how to properly override object.GetHashCode() According to [MSDN](http://msdn.microsoft.com/en-us/library/system.object.gethashcode.aspx), a hash function must have th...

20 Jun at 09:12

What is the difference between using IEqualityComparer and Equals/GethashCode Override?

What is the difference between using IEqualityComparer and Equals/GethashCode Override? When i am using dictionaries sometimes I have to change the default Equals meaning in order to compare Keys. I s...

Implementation of Object.GetHashCode()

Implementation of Object.GetHashCode() I'm reading [Effective C#](https://rads.stackoverflow.com/amzn/click/com/0321658701) and there is a comment about `Object.GetHashCode()` that I didn't understand...

29 Aug at 13:57

When Should a .NET Class Override Equals()? When Should it Not?

When Should a .NET Class Override Equals()? When Should it Not? The VS2005 documentation [Guidelines for Overloading Equals() and Operator == (C# Programming Guide)](http://msdn.microsoft.com/en-us/li...

14 Mar at 20:6

Overriding GetHashCode for mutable objects?

Overriding GetHashCode for mutable objects? I've read about 10 different questions on when and how to override `GetHashCode` but there's still something I don't quite get. Most implementations of `Get...

8 Oct at 15:17

Object.GetHashCode

Object.GetHashCode My question may duplicate [Default implementation for Object.GetHashCode()](https://stackoverflow.com/questions/720177) but I'm asking again because I didn't understand the accepted...

23 May at 12:34

What to return when overriding Object.GetHashCode() in classes with no immutable fields?

What to return when overriding Object.GetHashCode() in classes with no immutable fields? Ok, before you get all mad because there are hundreds of similar sounding questions posted on the internet, I c...