Repeat Value
-
You can sort the ArrayList, then the duplicate values will be next to each other so that you easily can find them. Depending on what you use the list for, it might be much easier to remove the duplicate values before they even end up in the ArrayList. If you for example get the values from a database, it's much easier to just not fetch the duplicate values at all. You can use a Hashtable to make it easier to determine if a value already exists in the list.
--- b { font-weight: normal; }
-
You could do something like this :
void Main(string[] args) { ArrayList ar = new ArrayList(); ar.Add(5); ar.Add(2); ar.Add(6); ar.Add(5); ar.Add(8); ar.Add(9); ar.Add(1); ar.Add(1); ar.Add(9); ar.Add(5); RemoveDuplicates(ar); } void RemoveDuplicates(ArrayList ar) { ar.Sort(); for (int i = ar.Count - 1; i > 0; i--) { if (ar[i].Equals(ar[i - 1])) { ar.RemoveAt(i); } } }
--- "Drawing on my superior command of language I said nothing."