I have a List in which I select users from db each time a sql query runs with certain value and selects one user in the time thus I cannot limit identical users in sql.
I have list with:
list[0] = "jerry"
list[1] = "tom"
list[2] = "jerry"
I want any (first or last doesn't matter in my case) to be removed from the list.
Thanks
IEnumerable<string> uniqueUsers = list.Distinct();
You can also use a HashSet:
HashSet<string> uniqueUsers = new HashSet<string>(list);
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