Suppose this is my member class
class Member
{
public string CategoryId { get; set; }
public string MemberName { get; set; }
public int Distance { g
This should cover your needs:
var grouped = list.GroupBy(item => item.CategoryId);
var shortest = grouped.Select(grp => grp.OrderBy(item => item.Distance).First());
It first groups the items with the same CategoryId
, then selects the first from each group (ordered by Distance
).
Update: You could chain all of these together too, if you prefer:
var shortest = list.GroupBy(item => item.CategoryId)
.Select(grp => grp.OrderBy(item => item.Distance)
.First());