iequatable Questions

11

Solved

class Program { static void Main(string[] args) { List<Book> books = new List<Book> { new Book { Name="C# in Depth", Authors = new List<Author> { new Author { ...
Ise asked 2/9, 2009 at 3:50

4

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. ...
Munificent asked 19/8, 2009 at 12:8

5

Solved

I have an interface like this: public interface IFoo { int A {get;} int B {get;} } and I have multiple classes implementing IFoo. I want to check equality, not based on ReferenceEquality, but ...
Lippmann asked 21/2, 2011 at 13:2

4

Solved

What does IEquatable<T> buy you, exactly? The only reason I can see it being useful is when creating a generic type and forcing users to implement and write a good equals method. What am I m...
Lahdidah asked 19/3, 2010 at 11:27

4

Solved

I want my Food class to be able to test whenever it is equal to another instance of Food. I will later use it against a List, and I want to use its List.Contains() method. Should I implement IEquat...
Introgression asked 29/4, 2010 at 5:12

2

Solved

I'm struggling with implementing the IEquatable<> interface for a class. The class has a Parameter property that uses a generic type. Basically the class definition is like this: public clas...
Nursling asked 27/1, 2020 at 13:57

5

Solved

I want to compare a property instead of the entire object using a List[MyObject]. I therefore use IEquatable[MyObject] but the compiler still wants MyObject instead of the string property. Why? He...
Ona asked 3/12, 2012 at 14:34

5

Solved

Both the interfaces seem to compare objects for equality, so what are the major differences between them?
Nesmith asked 9/3, 2010 at 15:21

4

Solved

Anyone have any opinions on whether or not IEquatable<T> or IComparable<T> should generally require that T is sealed (if it's a class)? This question occurred to me since I'm writing a...
Cephalization asked 8/12, 2009 at 16:56

3

Solved

I'm implementing IEquatable<T>, and I am having difficulty finding consensus on the GetHashCode override on a mutable class. The following resources all provide an implementation where GetHa...
Tisman asked 1/3, 2018 at 17:43

3

Solved

Consider this code: public static void Main() { var item = new Item { Id = 1 }; IList list = new List<Item> { item }; IList array = new[] { item }; var newItem = new Item { Id = 1 }; ...
Jeanettajeanette asked 9/7, 2017 at 2:21

2

Solved

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 Contac...
Dactylography asked 15/3, 2010 at 2:27

2

Solved

Attempt #3 to simplify this question: A generic List<T> can contain any type - value or reference. When checking to see if a list contains an object, .Contains() uses the default EqualityComp...
Binnings asked 15/5, 2016 at 21:11

2

Solved

So I have an interface, lets call it IInterface. public interface IInterface : IEquatable<IInterface> { string Name { get; set; } int Number { get; } Task<bool> Update(); } Then I...
Spring asked 24/4, 2016 at 20:57

1

Solved

This question is for educational purposes only and I can solve it easily by using for loop that returns false on first mismatch. I am implementing IEquatable<CustomerFeedbackViewModel> on Cu...
Alert asked 2/2, 2016 at 9:56

2

Solved

I'm trying to do a Linq GroupBy on some objects using an explicit key type. I'm not passing an IEqualityComparer to the GroupBy, so according to the docs: The default equality comparer Default ...
Letterperfect asked 6/11, 2009 at 8:55

4

Solved

I have an Address class in C# that looks like this: public class Address { public string StreetAddress { get; set; } public string RuralRoute { get; set; } public string City { get; set; } pu...
Gerontocracy asked 5/6, 2009 at 19:9

2

Solved

I am aware of the fact that I always have to override Equals(object) and GetHashCode() when implementing IEquatable<T>.Equals(T). However, I don't understand, why in some situations the Equa...
Riotous asked 10/2, 2015 at 15:5

2

Solved

I'm attempting to create a simple generic node class that conforms to the Comparable protocol so that I can easily compare nodes without accessing their key. When I attempt to write the < and ==...
Yuu asked 29/7, 2014 at 21:54

9

Solved

Suppose I want to be able to compare 2 lists of ints and treat one particular value as a wild card. e.g. If -1 is a wild card, then {1,2,3,4} == {1,2,-1,4} //returns true And I'm writing a clas...
Unthinkable asked 22/7, 2014 at 15:37

1

Solved

I've got a class which consists of two strings and an enum. I'm trying to use instances of this class as keys in a dictionary. Unfortunately I don't seem to be implementing IEquatable properly. Her...
Murrhine asked 4/3, 2014 at 14:56

5

Solved

I want to understand the scenarios where IEqualityComparer<T> and IEquatable<T> should be used. The MSDN documentation for both looks very similar.
Warrick asked 16/2, 2012 at 18:27

5

Many of my questions here on SO concerns IEquatable implementation. I found it being extremely difficult to implement correctly, because there are many hidden bugs in the naïve implementation, and ...
Bougie asked 20/8, 2009 at 16:48

3

Solved

I know the importance of overriding GetHashCode when implementing custom equality checks - for which I have implemented IEquality<T> interface, and also the difference between generic and non...
Pownall asked 6/12, 2012 at 10:34

3

I noticed that EF's DbSet.Add() is quite slow. A little googling turned up a SO answer that promises up to 180x performance gains: https://mcmap.net/q/444766/-why-does-dbset-add-work-so-slow Howe...
Predicative asked 20/3, 2012 at 6:27

© 2022 - 2024 — McMap. All rights reserved.