Linked Questions
171 questions linked to/from Why is it important to override GetHashCode when Equals method is overridden?
20
votes
4
answers
3k
views
What can go wrong if one fails to override GetHashCode() when overriding Equals()? [duplicate]
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 ...
5
votes
2
answers
3k
views
Why do I need to override the .Equals and GetHashCode in C# [duplicate]
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 ...
3
votes
3
answers
1k
views
implementing Equals but not GetHashCode in c# [duplicate]
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.
...
3
votes
2
answers
1k
views
Why do we need GetHashCode() function in the Object Model Project? [duplicate]
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 ...
-1
votes
2
answers
938
views
What's the relation between GetHashCode and Equals in a IEqualityComparer implementation? [duplicate]
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 ...
0
votes
1
answer
904
views
Create unique HashSet of objects [duplicate]
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 ...
0
votes
0
answers
659
views
C# Hash Function for Dictionary Lookup [duplicate]
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(...
-6
votes
3
answers
356
views
What is this hash come from? [duplicate]
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 !...
0
votes
1
answer
334
views
Why is GetHashCode important and where can we use it? [duplicate]
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?
1
vote
0
answers
140
views
C# How do we use Object.GetHashCode() [duplicate]
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 ...
1
vote
1
answer
191
views
How do I make sure 2 instances of my class have the same hash code? [duplicate]
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
{
...
193
votes
21
answers
120k
views
Comparing two collections for equality irrespective of the order of items in them
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'...
164
votes
10
answers
163k
views
How to check if all list items have the same value and return it, or return an “otherValue” if they don’t?
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 ...
125
votes
7
answers
241k
views
How to use the IEqualityComparer
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 ...
107
votes
7
answers
90k
views
C# .Equals(), .ReferenceEquals() and == operator
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 ...