Questions tagged [gethashcode]

GetHashCode is method of base Object class of .Net Framework.

GetHashCode is method of base Object class of .Net Framework. A hash code is a numeric value that is used to identify an object during equality testing. It can also serve as an index for an object in a collection. The GetHashCode method is suitable for use in hashing algorithms and data structures such as a hash table.

Important notes

  • Equality of GetHashCode value doesn't necessarily imply equality of objects. The equality must be verified using Equals.
  • Inequality of GetHashCode necessarily means inequality of objects.
344 questions
-1
votes
1 answer

Unexpected GetHashCode behavior in Vector3D

I have found some weird behavior with the Vector3D class. Given two Vector3Ds with rearranged X/Y/Z values (e.g. [0,0,1], [0,1,0] or [3,1,4],[1,3,4]), calling GetHashCode results in the same value. If you check to see if the vectors are equal via…
Jeremy Herrman
  • 472
  • 6
  • 14
-1
votes
1 answer

32-bit GetHashCode() on a 64-bit .NET 4.5 CLR

On a 64-bit .NET 4.5 platform, is there anyway to compute what would be the results of a string's GetHashCode() method on a 32-bit .NET 4.5 platform? It is obvious this is not a good idea. That has been asked and explained here and here. Only an…
Joshcodes
  • 8,513
  • 5
  • 40
  • 47
-1
votes
2 answers

what is the correct way for overriding string.GetHashCode()?

I am looking to create a custom string.GetHashCode() method for some of the strings used in a program namespace (as recommended on the string.GetHashCode() msdn page here) Unfortunately the string class is inheritance sealed. The closest I have…
stackuser83
  • 2,012
  • 1
  • 24
  • 41
-1
votes
2 answers

how do I use an equals method to check fields in different objects to see if they are equals?

How do i use an objects equals() and the gethashcode() method to check the an objects field value to see if it is true? for example order numbers I have several different objects that I am initiating and I need to run an equals() method to check…
user2981049
  • 11
  • 1
  • 2
-1
votes
2 answers

C# Is this a bad way to implement GetHashCode?

I'm trying to implement GetHashCode for an object that I have overridden Equals on. public override bool Equals(object obj) { var myobject = obj as MyObject; if (myobject == null) return false; if (myobject.SomeProperty == null…
ConditionRacer
  • 4,418
  • 6
  • 45
  • 67
-1
votes
2 answers

How to specify that some class's instances should not be used as dictionary keys?

I am interested in your opinion regarding an issue that came up while implementing a small library for writing integration/system tests in C#. The library is composed of 2 parts: a test Authoring API and a test Runtime API. The test writer uses the…
Ikaso
  • 2,268
  • 19
  • 26
-1
votes
3 answers

What interfaces must I implement to make a List or Dictionary concatenate two values as a key

I need to make my custom object work correctly in a Dictionary, List, etc... so that I can change properties of the object, and allow it to be resorted, and not orphaned. The last time I attempted overriding GetHashCode(), I orphaned objects when I…
makerofthings7
  • 60,103
  • 53
  • 215
  • 448
-2
votes
3 answers

IEqualityComparer GetHashCode return same values when items are not equal?

In the "Notes to Implementers" section in the documentation for the GetHashCode method of the IEqualityComparer interface, it states: Implementations are required to ensure that if the Equals method returns true for two objects x and y, then…
casperOne
  • 73,706
  • 19
  • 184
  • 253
-2
votes
1 answer

Parallel loop with insert into table

I'm trying to insert into table in a parallel loop. public static void idToHashEncoder() { string sql = ""; Stopwatch sw = new Stopwatch(); sw.Start(); Parallel.For(0, 1001, i => { sql = string.Format(@"INSERT INTO…
-2
votes
1 answer

GetHashCode With Generic Collection Returns Different Values

It looks like hash code issues and implementing your own equality logic have been beaten to death, but I cannot seem to find a definitive answer to this. I have a custom object (Step) that overrides Equals, GetHashCode, ==, and != as suggested by…
user1617242
  • 53
  • 1
  • 5
-2
votes
2 answers

When would you ever want a GetHashCode() to collide?

Is there a case when a hashcode collision would be beneficial? (Other than when the objects are identical, of course.) EDIT: beneficial meaning to calculate the hashcode in less cpu cycles, or use less memory in the calculation. I guess a…
Protiguous
  • 89
  • 2
  • 9
-3
votes
1 answer

wpf binding not refreshing if equals and gethashcode (NO IPROPERTYCHANGED NEEDED!)

My WPF binding is not working because my viewmodel has overwritten Equals and GetHashCode. If i comment it out (region Object-Stuff), everything works fine. Further info about my reasons: All my viewmodels have an Id. I load data with Id=1 and set…
Dosihris
  • 145
  • 9
-5
votes
2 answers

what are the methods "public override bool equals(object obj)" and "public override int gethashcode()" doing?

I started to learn about Operator overloading, and in an example code that I found those two methods were (public override bool equals(object obj) and public override int gethashcode()). I didn't understand why they are there because when I dubugged…
IdoShamriz
  • 63
  • 1
  • 3
  • 7
1 2 3
22
23