Linq query to get the distinct values in a list

后端 未结 7 1759
攒了一身酷
攒了一身酷 2021-02-08 22:34

Suppose this is my member class

class Member 
{
    public string CategoryId { get; set; }
    public string MemberName { get; set; }
    public int Distance { g         


        
7条回答
  •  忘掉有多难
    2021-02-08 23:21

    You can use the following code:

    List sourceList = new List();
    IEnumerable result = 
        (sourceList as IEnumerable)
        .Distinct()
        .OrderBy(value => value.CategoryId);
    

提交回复
热议问题