I want to get individual values โโin a list, but not a standard equality comparison.
I want to do something like this:
return myList.Distinct( (x, y) => x.Url == y.Url );
I canโt, there will be no extension method in Linq that will do this - only one that accepts IEqualityComparer .
I can crack it with this:
return myList.GroupBy( x => x.Url ).Select( g => g.First() );
But that seems messy. It is also not quite the same - I can only use it here because I have one key.
I can also add my own:
public static IEnumerable<T> Distinct<T>( this IEnumerable<T> input, Func<T,T,bool> compare ) {
But rather, it looks like it should be there in the first place.
Does anyone know why this method is not?
Did I miss something?
c # linq distinct
Keith Feb 06 '09 at 11:51 2009-02-06 11:51
source share