Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
3.50/5 (3 votes)
See more:
Good Morning ALL

I have an Arralist for example
<br />1<br />2<br />3<br />4<br />5<br />2<br />4<br />3


Now i need to Find Duplicates in this array list. how can i get the Duplicated


Thank you

Posted

ArrayList is too old and try to avoid unless you are on .NET 1.1.

Method 1
list.Sort();<br />int i = 0;<br />while (i < list.Count - 1)<br />{<br />   if ((int)list[i] == (int)list[i + 1])<br />        list.RemoveAt(i);<br />   else<br />        ++i;<br />}
Method 2
ArrayList target = new ArrayList(list.ToArray().Distinct().ToArray());
This works only when you have System.Linq namespace imported.

If you use .NET 3.5, use HashSet(T) class. It will not allow duplicate entries to be created. For .NET 2.0 or later, use List(T) other than ArrayList.

:)

 
Share this answer
 
You should take "C#" out of your sig until you learn it.

This has been asked/answered at least twice before. It's homework, isn't it?

 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900