tags:

views:

67

answers:

3

How would I specify the id field of an object in a list of objects as the disctinction?

Selections.Distinct();

A: 

You can create an equality comparer by implementing the IEqualityComparer<TSource> interface. You then pass your ConcreteEqualityComparer to Distinct():

Selections.Distinct(new ConcreteEqualityComparer());
Justin Niessner
If he's using LINQ to SQL (which is how he's tagged this, though his code does look more like LINQ to Objects), in which case this won't work, because the equality comparer can't be translated to SQL. (It will work in LINQ to Objects, of course.)
itowlson
A: 

You'll need to implement IEqualityComparer<T>

Rubens Farias
A: 

IEqualityComparer sample implementation. Shameless link to my answer for one similar SO question

ram