iequatable

Comparing two List<MyClass> 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 List<MyClass>(); var ListB = new List<MyClass>(); // Add distinct objects that are equal to one another t...

Cascading IEquatable(Of T)

Hello! 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 etc. How is this done? ...

GetHashCode on null fields?

How do I deal with null fields in GetHashCode function? Module Module1 Sub Main() Dim c As New Contact Dim hash = c.GetHashCode End Sub Public Class Contact : Implements IEquatable(Of Contact) Public Name As String Public Address As String Public Overloads Function Equals(ByVal other As Contact) As Boolean _ ...

How to implement IEquatable<T> when mutable fields are part of the equality - Problem with GetHashCode

Hello! I am using Entity Framework in my application. I implemented with the partial class of an entity the IEquatable<T> interface: Partial Class Address : Implements IEquatable(Of Address) 'Other part generated Public Overloads Function Equals(ByVal other As Address) As Boolean _ Implements System.IEquatable(Of Address).Equa...

C# dictionary uniqueness for sibling classes using IEquatable<T>

I would like to store insances of two classes in a dictionary structure and use IEquatable to determine uniqueness of these instances. Both of these classes share an (abstract) base class. Consider the following classes: abstract class Foo { ... } class SubFoo1 : Foo { ... } class SubFoo2 : Foo { ... } The dictionary will b...

What's the difference between IEquatable and just overriding Object.Equals() ?

I want my Food class to be able to test whenever it is equal to another class. I will later use it against a List, and I want to use its List.Contains() method. Should I implement IEquatable or just override Object.Equals()? From MSDN: This method determines equality by using the default equality comparer, as defined by the objec...

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 version. In the xaml below, you will see the four columns that I have in my grid. The SVOs co...

How to structure classes to Implement IEquatable and ISerializable

Hi Good Sirs. 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; set; } bool IsActive { get; set; } } and a bunch of derived classes l...