You need to override Equals
and GetHashCode
for BarObject
because the EqualityComparer.Default<BarObject>
is reference equality unless you have provided overrides of Equals
and GetHashCode
(this is what Enumerable.Distinct<BarObject>(this IEnumerable<BarObject> source)
uses). Alternatively, you can pass in an IEqualityComparer<BarObject>
to Enumerable.Distinct<BarObject>(this IEnumerable<BarObject>, IEqualityComparer<BarObject>)
.
↧
Answer by jason for This code returns distinct values. However, what I want is to return a strongly typed collection as opposed to an anonymous type
↧