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
3
votes
5 answers
Implementing IEquatable in a mutable type
I have a class that represents an external physical measuring device. The simplified version looks like this:
public class Device {
public string Tag { get; set; }
public int Address { get; set; }
}
Tag is a user-defined value for…

qxn
- 17,162
- 3
- 49
- 72
3
votes
1 answer
C# - Can't override ==
I have the following class (built for Unity Game Engine)
using System;
using System.Collections.Generic;
using UnityEngine;
public class Biome : ScriptableObject, IEquatable
{
// ...
//
// IEquatable
//
public bool…

Enrique Moreno Tent
- 24,127
- 34
- 104
- 189
3
votes
6 answers
in IEquatable implementation is reference check necessary
I have a class that imlements IEquatable. Is it necessary to do a refrence check in Equals() or is it taken care of in the framework?
class Foo : IEquatable
{
int value;
Bar system;
bool Equals(Foo other)
{
return…

John Alexiou
- 28,472
- 11
- 77
- 133
3
votes
2 answers
How can two generic linked list in swift can be compared?
I have a generic linked list and I can check if two linked list are equal if each of the node value are same and are in order.
I have a function which divides linked list in two part and later I want to check two list has same value in it's…

manismku
- 2,160
- 14
- 24
3
votes
1 answer
SequenceEqual different results
in the code below calling SequenceEqual on generic list return true (as expected) when List is defined with class generic type (EquatableClass.Equals<> is called).
If list is defined with IEquatable interface, Equals method is not called and result…

user4662448
- 41
- 5
3
votes
3 answers
Make List Distinctable with IEquatable
I wanted to make my Class Sortable(By Age) when it stored in List.
I read this : IComparable Vs IComparer and I maked my class Sortable .
public class Student : IComparable
{
public int ID { get; set; }
public string Name { get;…

Parsa
- 7,995
- 2
- 27
- 37
3
votes
4 answers
What's the difference between obj1.Equals(obj2) and static Object.Equals(obj1, obj2) in c#?
from the documentation by Microsoft, both Equals-methods are essentially the same. But I just stumbled across something very strange.
in my Silverlight project I have two instances of the same class that overrides Equals.
If I ask for…

Rocko
- 31
- 1
3
votes
1 answer
Equatable in Swift
I am trying to define Equatable using Swift structs. I am getting an error on the line func == saying Operators are only allowed at global scope.
struct ShoppingList {
var shoppingListId :NSNumber
var title :String
init(title :String)…

john doe
- 9,220
- 23
- 91
- 167
3
votes
3 answers
Auto implement Unique ID in a hashable class
I create a new class that I want to be Hashable and Equatable so I can easily loop through it, a class example is below:
class MyClass: Hashable {
var uid: Int
var myName: String
var myAge:Int
var hashValue: Int {
return…

Icaro
- 14,585
- 6
- 60
- 75
3
votes
2 answers
Find index of object in an array of type [SomeProtocol]
I have an array called subscribers that stores objects which conform to the protocol JABPanelChangeSubscriber. The protocol is declared as
public protocol JABPanelChangeSubscriber {
}
and my array is declared as:
var subscribers =…

jeremyabannister
- 3,796
- 3
- 16
- 25
3
votes
3 answers
IEquatable breaks loading of Entity Framework entities
I want to compare records to see if there are differences between them.
Person table:
ID Name Address
--------------------------------
1 John Smith 123 A Street
2 John Smith 123 A Street
3 John Smith 234 B…

jamesSampica
- 12,230
- 3
- 63
- 85
3
votes
1 answer
Should I Allow Asymmetric Equals?
I have a C# type for which it makes logical sense to compare for equality with int. Call this type Number.
However, I can't make Equals symmetric, because I can't change Int32.Equals(object other). So, should I permit the asymmetric equality, like…

Xenoprimate
- 7,691
- 15
- 58
- 95
3
votes
3 answers
Comparing two List in C#
I have a class called
MyClass
This class inherits IEquatable and implements equals the way I need it to. (Meaning: when I compare two MyClass tyupe objects individually in code, it works)
I then create two List:
var ListA = new…

Matt
- 25,943
- 66
- 198
- 303
3
votes
4 answers
How do C# Linq extension methods perform equality comparison?
So, the following lambda expression is not returning any elements in the collection, even though while stepping through I was able to verify that 1 item matches the criteria. I've added a sample of the class with it's IEquatable…

Carlos Bittencourt
- 352
- 1
- 3
- 9
3
votes
1 answer
What happens when ==, CompareTo(), and Equals() do not agree?
I have a program I wrote some years back to find "good" binary operators for bytes; byte A is left multiplied by byte B to yield byte C. The operator is defined as 256x256 byte matrix. A stripped down version of the class implementation is…

John Washburn
- 568
- 1
- 5
- 11