I\'ve been using LINQ for a while now, but seem to be stuck on something with regards to Unique items, I have the folling list:
List stock = new Lis
static class EnumerableEx
{
// Selectively skip some elements from the input sequence based on their key uniqueness.
// If several elements share the same key value, skip all but the 1-st one.
public static IEnumerable uniqueBy( this IEnumerable src, Func keySelecta )
{
HashSet res = new HashSet();
foreach( tSource e in src )
{
tKey k = keySelecta( e );
if( res.Contains( k ) )
continue;
res.Add( k );
yield return e;
}
}
}
// Then later in the code
List res = src.uniqueBy( elt => elt.Type ).ToList()