Distinct not working with LINQ to Objects

后端 未结 9 1732
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 12:20
class Program
{
    static void Main(string[] args)
    {
        List books = new List 
        {
            new Book
            {
                


        
9条回答
  •  忘了有多久
    2020-11-22 12:50

    There is one more way to get distinct values from list of user defined data type:

    YourList.GroupBy(i => i.Id).Select(i => i.FirstOrDefault()).ToList();
    

    Surely, it will give distinct set of data

提交回复
热议问题