Distinct in linq?

前端 未结 5 1264
我寻月下人不归
我寻月下人不归 2020-12-31 20:07

I am wondering how can I achieve this?

I want to get only distinct names from a collection of objects

MyObject a = new Object();
a.Name = \'One\';
a.         


        
5条回答
  •  囚心锁ツ
    2020-12-31 20:19

    Maybe something like this can help?

    var distinctItems = items
         .GroupBy(x => x.PropertyToCompare)
         .Select(x => x.First());
    

提交回复
热议问题