Distinct in linq?

前端 未结 5 1266
我寻月下人不归
我寻月下人不归 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:29

    This populates both the Text and Value fields:

       myCollection.Select(x => x.Name).Distinct()
          .Select(x => new MyClassToStore { Text = x, Value = x }).ToList();
    

提交回复
热议问题