A
A
Alexander Kosheverov2013-11-22 23:29:46
C++ / C#
Alexander Kosheverov, 2013-11-22 23:29:46

How to remove duplicate values ​​in a list of objects in C#?

There is a Variables class (hereinafter V) with ID and Name fields. There is also a Combination Class (hereinafter C) with a SortedSet of class V objects and some other fields. And, in fact, there is a List Model
By the end of the algorithm, I still have the same values ​​​​of class C in this list. Distinct does not help, for classes V and C, inheritance of the IEquatable and IComparable interfaces is implemented.
I checked them manually - they work as they should.
Can you tell me how to remove duplicates in the list?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Guketlev, 2013-11-22
@Iworb

In general, it is possible that Returns distinct elements from a sequence by using the default equality comparer to compare values. And for reference type, default will be comparison of references.
There is an overload that takes IEqualityComparer http://msdn.microsoft.com/en-us/library/vstudio/bb338049 (v=vs.100).aspx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question