Get distinct items from a list
Example of a more complex distinct'ing....
licenseLookupItems = tmpList
.GroupBy(x => new {x.LicenseNumber, x.Name, x.Location, x.Active, x.Archived})
.Select(p => p.FirstOrDefault())
.Select(p => new LicenseNumberLookupItem
{
LicenseNumber = p.LicenseNumber,
Name = p.Name,
Location = p.Location,
Active = p.Active,
Archived = p.Archived
})
.ToList();
Try:
var g = collection.Select(i => i.Property1).Distinct();
Could you post some source code so that we can give you a better example?
EDIT:
In my example, I have a collection collection
which contains numerous instances of your class. I'm then selecting Property1
from each class, filtering to the distinct values of that property.
This should work,
List<int> result = YourListObject.Select(o => o.FirstInteger).Distinct().ToList();
I have found this useful and working fine for me for strings.
var distinctNames = (from d in YourList select d).Distinct();
Hope this is useful for some one like me searching for details in SO.