Linked Questions

36 votes
6 answers
61k views

As you know, GetHashCode returns a semi-unique value that can be used to identify an object instance in a collection. As a good practice, it is recommended to override this method and implement your ...
Den's user avatar
  • 16.9k
75 votes
1 answer
92k views

I'd like to hear from the community on how I should go about implementing GetHashCode (or override it) for my object. I understand I need to do so if I override the equals method. I have implemented ...
Zivka's user avatar
  • 959
10 votes
1 answer
13k views

Possible Duplicate: What is the best algorithm for an overridden System.Object.GetHashCode? What constitutes a good implementation of the GetHashCode method? I did some googling, and found some ...
GurdeepS's user avatar
  • 67.6k
12 votes
2 answers
12k views

Possible Duplicate: What is the best algorithm for an overridden System.Object.GetHashCode? I need to override GetHashCode method for a type which consists of three strings. Here is my code: ...
SiberianGuy's user avatar
  • 25.5k
12 votes
2 answers
7k views

In this MSDN article http://msdn.microsoft.com/en-us/library/ms132123.aspx it discusses the Class Equalitycomparer and has an example.In this example about comparing boxes it has this class - class ...
Paul Stanley's user avatar
  • 2,191
7 votes
1 answer
10k views

I have to following classes: public class NominalValue { public int Id {get; set;} public string ElementName {get; set;} public decimal From {get; set;} public decimal To {get; set;} ...
Masoud's user avatar
  • 8,246
3 votes
1 answer
6k views

Possible Duplicate: What is the best algorithm for an overridden System.Object.GetHashCode? This is known to us that if we override the Equals method of Object in our custom types, we should also ...
S2S2's user avatar
  • 8,560
2 votes
1 answer
4k views

So, I have this Struct. It has some functions and operators overridden, but that's not so important. public struct Vector3 { public float X, Y, Z; } I'm filtering a Collection of these via a ...
Griizz's user avatar
  • 175
2 votes
1 answer
6k views

First of all, I found an implementation of GetHashCode for a 3D integer vector, but I can't figure out if this is a good one or not (at least I'm not 100% sure): public struct Vector3i { public ...
Casto's user avatar
  • 305
3 votes
2 answers
3k views

I want to use a byte array as a lookup key in a concurentDictionary. Currently I solve this by using a custom EqualityComparer<byte[]>. This works fine, but I do realize that my hashcode ...
Roger Johansson's user avatar
1 vote
1 answer
3k views

I have a var itemList = new List<Item>() and a var searchSet = new HashSet<TestItem>(new TestItemComparer()); For each element in the itemList I look for its existance in the ...
Elisabeth's user avatar
  • 21.4k
4 votes
1 answer
3k views

Duplicate: What is the best algorithm for an overridden System.Object.GetHashCode? If you've written an object with a variety of data-members, how do you intelligently implement GetHashCode()? One ...
abelenky's user avatar
  • 65k
2 votes
1 answer
2k views

I'm using this function for a key in C#'s hash map like class, "Dictionary". x, y and z are Int16. public override int GetHashCode() { return (x << 16) | (UInt16)y; } How could I extend ...
alan2here's user avatar
  • 3,335
3 votes
2 answers
806 views

According to MSDN GetHashCode Method: public struct Point { private int x; private int y; public Point(int x, int y) { this.x = x; this.y = y; } public ...
Allen Chen's user avatar
0 votes
1 answer
1k views

I have a struct that overrides the Equals() method and the compiler complains about GetHashCode() not being overridden. My struct: private struct Key { ... public override int ...
ViRuSTriNiTy's user avatar
  • 5,205

15 30 50 per page
1
2 3 4 5
21