Linked Questions

20 votes
4 answers
3k views

Possible Duplicate: Why is it important to override GetHashCode when Equals method is overridden? In C#, what specifically can go wrong if one fails to override GetHashCode() when overriding ...
jon37's user avatar
  • 1,399
5 votes
2 answers
3k views

I am using Entity Framework 5. In my C# code I want to compare if two objects are equal. If there are not then I want to issue an update. I have been told I need to override the .Equals method and ...
user avatar
3 votes
3 answers
1k views

Possible Duplicate: Why is it important to override GetHashCode when Equals method is overriden in C#? I dont implement the GetHashCode method of the Object class. so I get a number of warnings. ...
user avatar
3 votes
2 answers
1k views

Possible Duplicate: Why is it important to override GetHashCode when Equals method is overriden in C#? I was looking into the following class in my Object Model and could not understand the ...
Pankaj's user avatar
  • 10.2k
-1 votes
2 answers
938 views

I have a class A that inherits from a class B and implements IEqualityComparer<A>. This means class A provides its own implementation of both Equals and GetHashCode methods. So far so good. The ...
Veverke's user avatar
  • 11.6k
0 votes
1 answer
904 views

I created a class Person and a HashSet. If I add the same person to the HashSet, it is not aware the Person is already present and it will add the same person multiple times. What function do I need ...
Nick_F's user avatar
  • 1,125
0 votes
0 answers
659 views

I am trying to check a Dictionary whether or not a certain Object is contained as a key: Dictionary<Order, int> occurence = new Dictionary<Order, int>(); if (occurence.ContainsKey(...
Curunir's user avatar
  • 1,308
-6 votes
3 answers
356 views

I can show a hash code like this : string str = "Hello World !"; MessageBox.Show(str.GetHashCode().ToString()); This is very simple , Message box return hash code of "Hello World !...
Sinaw's user avatar
  • 61
0 votes
1 answer
334 views

Possible Duplicate: Why is it important to override GetHashCode when Equals method is overriden in C#? Why is GetHashCode important and where can we use it?
oss's user avatar
  • 11
1 vote
0 answers
140 views

Sure, hascodes are used in hastables and collections but what about that: class TwoDPoint : System.Object{ public readonly int x, y; //...left out some code public override int ...
Noël Widmer's user avatar
  • 4,582
1 vote
1 answer
191 views

How do I ensure two different instances of a class have the same hash code? So when one of them is in a HashSet, the Contains function returns true. Here is my code: public class Position { ...
MisterBirs's user avatar
193 votes
21 answers
120k views

I would like to compare two collections (in C#), but I'm not sure of the best way to implement this efficiently. I've read the other thread about Enumerable.SequenceEqual, but it's not exactly what I'...
mbillard's user avatar
  • 39k
164 votes
10 answers
163k views

If all the items in a list have the same value, then I need to use that value, otherwise I need to use an “otherValue”. I can’t think of a simple and clear way of doing this. When the list is empty it ...
Ian Ringrose's user avatar
  • 52.2k
125 votes
7 answers
241k views

I have some bells in my database with the same number. I want to get all of them without duplication. I created a compare class to do this work, but the execution of the function causes a big delay ...
Akrem's user avatar
  • 4,662
107 votes
7 answers
90k views

My understanding of these three was: .Equals() tests for data equality (for the lack of a better description). .Equals() can return True for different instances of the same object, and this is the ...
999999's user avatar
  • 1,943

15 30 50 per page
1
2 3 4 5
12