I have a customers
List(of String) on which I am trying to find the duplicate customers.
If Not customers.Count = customers.Distinct.ToList.Count Then
customers = customers.Except(customers.Distinct.ToList)
End If
But I get the following exception:
InvalidCastException Unable to cast object of type '<ExceptIterator>d__99`1[System.String]' to type
'System.Collections.Generic.List`1[System.String]'.
Is this the right way to find duplicates in a list?
customers = customers.GroupBy(Function(m) m) _
.Where(Function(g) g.Count() > 1) _
.Select(Function(g) g.Key).ToList
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With