开发者

How to extract duplicate value in arraylist in c# [duplicate]

This question already has answers here: 开发者_开发问答 Remove duplicates from a List<T> in C# (32 answers) Closed 7 years ago.

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜