Find duplicates in List(Of String) in VB.NET

前端 未结 2 943
傲寒
傲寒 2021-01-06 08:10

I have a customers List(of String) on which I am trying to find the duplicate customers.

If Not customers.Count = customers.Distinct.ToList.Coun         


        
相关标签:
2条回答
  • 2021-01-06 08:33

    The VB version:

    Dim duplicates = listOfItems.GroupBy(Function(i) i)_
                                .Where(Function(g) g.Count() > 1)_
                                .[Select](Function(g) g.Key)
    

    C#:

    var duplicates = customers.GroupBy(x => x)
                              .Where(g => g.Count() > 1)
                              .Select(g => g.Key);
    
    0 讨论(0)
  • 2021-01-06 08:34
    customers = customers.GroupBy(Function(m) m) _
                     .Where(Function(g) g.Count() > 1) _
                     .Select(Function(g) g.Key).ToList
    
    0 讨论(0)
提交回复
热议问题