Equals

Refers to Java equals method, indicating whether some object is "equal to" this one.

Gethashcode

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

Equivalent performance implementation

Quality Example
Faster equivalent

"Even though gethashcode itself should be fast it s not mostly faster than equivalent equals"

from question "Using GetHashCode to test equality in Equals override"

Faster

"And that is for performance reasons assuming that a gethashcode implementation should always be much faster than an equals implementation"

from question "How does Linq Except Compare results"

Slower

"If you do not implement gethashcode union will call equals which will work but is slower than gethashcode"

from question "MVC LINQ Union with compare IComparer vs IEqualityComparer"

Others

Quality Example
More specific

"Equals on the other hand can test accross a larger number of fields - ie its test is more specific than gethashcode comparisons"

from question "Linq2Sql - attempting to update but the Set statement in sql is empty"

Faster

"1 is comparison via gethashcode check if the hashcode of both objects are the same faster than equals"

from question "Comparison via Equals or HashCode. which is faster?"

Quicker

"Not sure about the overhead of calling gethashcode a few million times but comparing two ints is probably going to be a lot quicker than the equals object method"

from question "Efficient Object Equality C#"

"Gethashcode should be a lot quicker than equals but doesn t need to be unique"

from question "How do I generate a hashcode from a byte array in C#?"

Implementation much more expensive

"In the equals method only if you re certain the ensuing equals implementation is much more expensive than gethashcode which is not vast majority of cases"

from question "Using GetHashCode to test equality in Equals override"

More tolerant

"Override both methods but make gethashcode more tolerant than equals that means make unequal objects have the same hash code and not the opposite"

from question "Equal but not interchangeable"

Back to Home
Data comes from Stack Exchange with CC-BY-SA-3.0