I have a class Items
with properties (Id, Name, Code, Price)
.
The List of Items
is populated with duplicated items.
F
Try this extension method out. Hopefully this could help.
public static class DistinctHelper
{
public static IEnumerable DistinctBy(this IEnumerable source, Func keySelector)
{
var identifiedKeys = new HashSet();
return source.Where(element => identifiedKeys.Add(keySelector(element)));
}
}
Usage:
var outputList = sourceList.DistinctBy(x => x.TargetProperty);