LINQ's Distinct() on a particular property

后端 未结 20 2093
一向
一向 2020-11-21 05:05

I am playing with LINQ to learn about it, but I can\'t figure out how to use Distinct when I do not have a simple list (a simple list of integers is pretty easy

20条回答
  •  [愿得一人]
    2020-11-21 05:40

    You can use DistinctBy() for getting Distinct records by an object property. Just add the following statement before using it:

    using Microsoft.Ajax.Utilities;

    and then use it like following:

    var listToReturn = responseList.DistinctBy(x => x.Index).ToList();
    

    where 'Index' is the property on which i want the data to be distinct.

提交回复
热议问题