How do I use Linq to obtain a unique list of properties from a list of objects?

前端 未结 5 1803
情书的邮戳
情书的邮戳 2020-12-04 11:56

I\'m trying to use Linq to return a list of ids given a list of objects where the id is a property. I\'d like to be able to do this without looping through each object and p

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 12:10

    When taking Distinct we have to cast into IEnumerable too. If list is model means, need to write code like this

     IEnumerable ids = list.Select(x => x).Distinct();
    

提交回复
热议问题