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
.
:)