Interface, which defines a generalized method that a value type or class implements to create a type-specific method for determining equality of instances.
Questions tagged [iequatable]
165 questions
1
vote
2 answers
Should == operator behave exactly as Equals()?
Let's consider Polygon class. Check for equality should compare references most of the time, but there are many situations where value equality comes in handy (like when one compares two polygons with Assert.AreEqual).
My idea is to make value…

matt-pielat
- 1,659
- 3
- 20
- 33
1
vote
1 answer
Unreachable code when overriding Object.Equals and implementing IEquatable<>?
I'm a litte bit confused right now. From my understanding the .NET runtime will pick the overloaded method that best suits the given parameter's type. So I would think, that in the snippet below the method Equals(object obj) will never be called…

markus
- 177
- 1
- 13
1
vote
1 answer
Why does IntPtr not implement IEquatable?
I was seeing a rather large amount of garbage collector stalls in my application, so I profiled it, and saw that a lot of garbage was being generated by a method of mine that did nothing more than this:
return Address.Equals(other.Address)
Where…

Xenoprimate
- 7,691
- 15
- 58
- 95
1
vote
2 answers
How to implement IEquatable when mutable fields are part of the equality - Problem with GetHashCode
I am using Entity Framework in my application.
I implemented with the partial class of an entity the IEquatable interface:
Partial Class Address : Implements IEquatable(Of Address) 'Other part generated
Public Overloads Function Equals(ByVal…

Shimmy Weitzhandler
- 101,809
- 122
- 424
- 632
1
vote
1 answer
Comparing objects as properties using Equatable in Swift
AMRoute class has two properties, city1 & city2, of type AMCity class.
Numerous AMRoutes are stored in an array, arrayOfRoutes.
When creating a new route, I first need to ensure no routes exist with two given cities.
I am having a hard time…

Justin Moore
- 884
- 2
- 9
- 22
1
vote
1 answer
IEquatable<'1> on interface
So, I've got a interface for entities that requires them to expose their identity.
public interface IEntity {
public TIdentity Id { get; }
}
Now I need to be able to compare two entities which each other, but I can't rely on the…

xvdiff
- 2,179
- 2
- 24
- 47
1
vote
1 answer
Cascading IEquatable(Of T)
I have several entities I need to make IEquatable(Of TEntity) respectively.
I want them first to check equality between EntityId, then if both are zero, should check regarding to other properties, for example same contact names, same phone number…

Shimmy Weitzhandler
- 101,809
- 122
- 424
- 632
1
vote
1 answer
IEquatable Operation is not valid due to the current state of the object
Ad I'm developping a project in C# I recently came over an error I can't understand.
First of all here is the core
if (CanPlay(target.Coord.X, target.Coord.Y))
{
target.Owner = m.Player;
this.MoveList.Push(m);
// Groupes
var friends…

Sladix
- 712
- 2
- 7
- 19
1
vote
1 answer
When overriding Object.Equals, is it appropriate to use the passed in object's Equals(MyType)?
For a simple example, assume you have two classes that are different in many ways, but can still be considered "equateable":
class WholeNumber: IEquatable {
int value;
public override bool Equals(object obj) {
if (obj…

Cemafor
- 1,633
- 12
- 27
1
vote
1 answer
Testing Collections of Objects for Equality using IEquatable
I have a class that I have made implement IEquatable so that when I'm testing I can easily compare IEnumerable collections of those objects using a call such as:
Assert.IsTrue(expected.SequenceEqual(actual));
This is currently working well but I…

davy
- 4,474
- 10
- 48
- 71
1
vote
2 answers
IEquatable on POCO identity field
I have POCOs from a SQL Server database that have an identity ID field. I would like to implement IEquatable so I can check if they're the same record, use .Contains() on List etc.
Assuming I will never need to compare unsaved instances, is it…

Sean
- 14,359
- 13
- 74
- 124
1
vote
2 answers
IEquatable - Overriding Equals - checking for nulls
I have a IEquatable method thus:
public bool Equals(TravelOptions other)
{
if (other == null) return false;
return
this.OutTravelType.Equals(other.OutTravelType) & //enum
this.BackTravelType.Equals(other.BackTravelType)…

nat
- 2,185
- 5
- 32
- 64
1
vote
2 answers
Suggested naming convention for IEquatable(Of T).Equals?
If I implement IEquatable(Of T) on my class and let Visual Studio (2010) auto-generate the required Equals method, I get this:
Public Function Equals1(ByVal other As Foo) As Boolean _
Implements System.IEquatable(Of Foo).Equals
End…

Jeff B
- 8,572
- 17
- 61
- 140
1
vote
2 answers
Having problems comparing two custom class objects
Possible Duplicate:
What is “Best Practice” For Comparing Two Instances of a Reference Type?
I have this custom Class for my application. There are two instances (A and B) of this class, which I'm trying to compare. However, I'm having problems;…

Ahmad
- 12,886
- 30
- 93
- 146
1
vote
4 answers
How to implement a GetHashCode compatible Equals method, when the space is greater than 32 bits?
In .NET you need that Equals(object) and GetHashCode() are compatible. But sometimes you can't:
public class GreaterThan32Bits
{
public int X { get; set; }
public int Y { get; set; }
}
Because the data density is greater than 32 bits, and…

Jader Dias
- 88,211
- 155
- 421
- 625