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
0
votes
1 answer
What is wrong with my IEquatable, IComparable implementation? SortedList throws ArgumentException
I am working on solving a puzzle online and stumbled upon this problem where given a 2D matrix and a number k, I need to return the kth smallest element in the matrix.
matrix = [
[ 1, 5, 9],
[10, 11, 13],
[12, 13, 15]
…

Sai
- 682
- 2
- 12
- 35
0
votes
1 answer
IEquatable within a tolerance, how to implement GetHashCode()
I have a Point3d struct which implements IEquatable in the following manner:
public override bool Equals(object obj) {
return obj is Point3d p && Equals(p);
}
public bool Equals(Point3d other) {
return Equals(other,…

Rob Kite
- 395
- 1
- 11
0
votes
1 answer
LINQ Distinct Not Working
I'm trying to select distinct instances from my class but it's not working, even after implements IEqualityComparer (as described here: https://msdn.microsoft.com/en-us/library/bb338049.aspx) AND IEquatable
Could someone help?
Public Class Teste
…

osmarditto
- 33
- 7
0
votes
2 answers
Compare two Lists
I have a class called TestResult which looks like this:
public class TestResult : IEquatable {
public TestResult(string labelName, List

Andrew
- 720
- 3
- 9
- 34
0
votes
0 answers
Make IEquatable safe for change
If I add IEquatable to a class, I know that I need to add overrides to Equals, GetHashCode and (for good practice) the == and != operators.
When I override these I will check various properties in the class. However, if another (naive) developer…

pos
- 1
- 2
0
votes
0 answers
NUnit GetResultState throws NullReferenceException
I'm getting an internal NullReferenceException from NUnit 2.6.4 while running a unit test fixture:
SetUp : System.NullReferenceException : Object reference not set to an instance of an object
at NUnit.Core.NUnitFramework.GetResultState…

Michael
- 59
- 6
0
votes
2 answers
System.Collections.Generic collection and IEquatable errors
I have the following class based on example code from Microsoft MSDN:
Imports System.Collections.Generic
Module SharedCode
Public Class Fund
Implements IEquatable(Of Fund)
'Class Fund must implement Function Equals(other As…

twellsles
- 1
- 2
0
votes
2 answers
Using LINQ GroupBy to group by reference objects instead of value objects
I want to GroupBy multiple objects in a list of records and not simply multiple values.
I am having trouble getting grouping to work with reference type objects. I have a collection of objects that contain Room, Type, and DateTime. Room, Type, and…

jwrightmail
- 907
- 1
- 13
- 24
0
votes
1 answer
Why do two equal instances of IEquatable return false?
Consider the following code
public class Rectangle : IEquatable
{
public int Width { get; set; }
public int Height { get; set; }
public bool Equals(Rectangle other)
{
return Width == other.Width
&&…

Matthew Layton
- 39,871
- 52
- 185
- 313
0
votes
1 answer
IEquatable.Equals from MSDN
I'm looking at IEquatable.Equals on MSDN. Specifically the section for the two Equals operators:
public override bool Equals(Object obj)
{
if (obj == null)
return false;
Person personObj = obj as Person;
if (personObj == null)
…

Storm
- 1,848
- 4
- 20
- 39
0
votes
1 answer
How to structure classes to Implement IEquatable and ISerializable
Been banging my head on this for a while now
The problem I have is trying to add the IEquatable behaviour so my derived classes can use set operations Intersect of ILink etc.
At the moment I have...
public interface ILink
{
int Linkid { get;…

MikeW
- 185
- 1
- 3
- 14
0
votes
1 answer
How would you go about making a List<> comparable?
I am using a Telerik GridView, and having an issue trying to sort a column that is made of of a List<>. In this forum entry, the Telerik team states that the grid can sort IComparable and group/filter IEquatable<> no matter of the Silverlight…

JSprang
- 12,481
- 7
- 30
- 32
0
votes
2 answers
C#, Which class fields/members should be considered when overriding GetHashCode and Equals?
There is this excelent question and answer about this topic:
Do I HAVE to override GetHashCode and Equals in new Classes?
As it mentions:
you only need to override them if you need value equality semantics. The System.Object implementation isn't…

Alberto Montellano
- 5,886
- 7
- 37
- 53
0
votes
1 answer
Equals Remove wrong assignment inside Equals
I have following class which i am using to compare some objects it looks like it:
Imports System.Collections.Generic
Public Class Part
Implements IEqualityComparer(Of Part)
Public _comparisonType As EqualsComparmission
Public Sub…

unknown
- 75
- 7
0
votes
0 answers
Implement IEquatable in WinRT solution?
So I have a bit of an issue. I'll see how well I can explain it.
I have a class that is shared between my windows phone foreground app and the background as a link (they both use the same file) this is because data is serialized from this class and…

user2704766
- 235
- 1
- 5
- 14