Questions tagged [iequatable]

Interface, which defines a generalized method that a value type or class implements to create a type-specific method for determining equality of instances.

165 questions
2
votes
3 answers

Hide base class method when implementing IEquatable

I'm looking for the best way to implement IEquatable in such a way that type checking is implicit. If I call Equals in a child class, I want to ensure that the type I'm comparing to is the same. See the stripped down example below. Two Child1…
helrich
  • 1,300
  • 1
  • 15
  • 34
2
votes
2 answers

IEquatable doesnt call Equals method

Ih, i am facing a problem with IEquatable (C#). As you can see in the following code, I got a class where i've implement IEquatable but it's "Equals" method is not getting reach. My objective is: I have a datetime column in my database and i would…
2
votes
2 answers

IEquatable implementation and operator overriding

A domain class T can be of type ValueObject: public class Coordinate: ValueObject { ... } ValueObject implements the IEquatable interface. I want each concrete implementation of ValueObject to provide implementation for bool…
Dave New
  • 38,496
  • 59
  • 215
  • 394
2
votes
2 answers

C# XNA: Trouble with Dictionaries

I'm new to C#. Perhaps I'm not implementing IEquatable properly, because objects of my type that should be considered the same are not. The class: class CompPoint : IComparable { public int X; public int Y; public…
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
2
votes
2 answers

How to implement Multi-type IComparable / IEquatable in C#

Let say I have the following class: public sealed class ScaleValue : IComparable, IComparable, IEquatable { public double Value { get; set;} public string Definition { get; set;} // interface…
2
votes
1 answer

LINQ Distinct with EqualityComparer.Default: IEquatable implementation ignored?

I have a class Foo with two fields where the Equals and GetHashCode methods have been overridden: public class Foo { private readonly int _x; private readonly int _y; public Foo(int x, int y) { _x = x; _y = y; } public override…
Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114
2
votes
2 answers

Using struct as key for dictionary and weird stuff is happening

Heres my struct... internal struct Coord : IEquatable { public int X { get; private set; } public int Y { get; private set; } public Coord(int x,int y) : this(){ X = x; Y = y;} //Overloaded operator functuions below …
Guye Incognito
  • 2,726
  • 6
  • 38
  • 72
2
votes
1 answer

IEquatable(Of T)/IEqualityComparer(Of T) Not Being Called

I have some code with two lists of objects. The first list is more inclusive than the second list. I wish to exclude items in the second list from the first list. After some research I found that the extension method Except is the way to do this. I…
cjbarth
  • 4,189
  • 6
  • 43
  • 62
2
votes
4 answers

IEnumerable.Except() and a custom comparer

I'm having troubles with the Except() method. Instead of returning the difference, it returns the original set. I've tried implementing the IEquatable and IEqualityComparer in the Account class. I've also tried creating a separate IEqualityComparer…
kanko
1
vote
3 answers

Does IEquatable cascade?

I have a very simply question regarding IEquatable. Given the following basic classes: public class Person { public string FirstName { get; set; } public string LastName { get; set; } public SalaryInformation…
Mick Walker
  • 3,862
  • 6
  • 47
  • 72
1
vote
1 answer

How to implement IEquatable> in C# for all types T?

I have a simple, generic container class in C# that looks something like this - public class Point { public T Data { get; } public string ID { get; } public Point(T x, string id) { this.Data = x; this.ID = id; …
Treker
  • 386
  • 2
  • 9
1
vote
0 answers

Implement IEquatable for struct, and pass by reference

Is it possible to implement IEquatable from a struct, but pass the compared argument by reference? Example: struct BigToCopy : IEquatable { int x, y, z, w, foo bar, etc; bool Equals(in BigToCopy other) // does not compile with…
myavuzselim
  • 365
  • 5
  • 8
1
vote
2 answers

Equatable package use for nullable value

I am using an extension for creating flutter class and I want to use equatable with it but it seem like it doesn't support nullable, is there a way to use it or do I have to use the generate equatable that the extension provide.
Ken
  • 57
  • 6
1
vote
1 answer

C# equality comparison fails

I am having trouble with the equality comparison via IEquatable<> in the following class I wrote: public class Bead: IEquatable { public string Name { get; set; } public Point2d Location { get; private set; } public void…
user366312
  • 16,949
  • 65
  • 235
  • 452
1
vote
1 answer

Is it possible to automatically handle List.Contains by comparing a property on the item?

Can we do something similar to List.Contains(myItem) in order to check if a property on an item in the list equals a property on myItem. (We have considered Contains and Exists, something like: if (orderLines.Contains(myLine)) { ... } but cannot…
Ole Lynge
  • 4,457
  • 8
  • 43
  • 57