How to extract duplicate value in arraylist in c# [duplicate]
I have a array list which have a list of a type, but all values are duplicated.
Specifically, my blog url is in my array list twice. How can I remove the duplicates?
arraylist.distinct();
Make sure you have using System.linq
at the top of your cs file.
The earlier answer is correct but just to add to it, you need to specify the type when you create the list. Arraylist does not have a distinct method by itself. Here is how you would do it,
List<string> foo = new List<string>();
foo.Add("sample");
foo.Add("sample");
...
IEnumerable bar = foo.Distinct();
Remove duplicates from a List<T> in C#
How do I remove repeated elements from ArrayList?
精彩评论