Removing duplicates in Arraylist with Unity3d

I want to be able to delete duplicates from an Arraylist. I know it can be done with HashSet but that doesn't work with Unity 2.x anymore. So, how can I delete duplicates in a quick and easy way?

You could iterate through the array with a double loop. Then you can check for each item in the array if another item with the same value exists and delete it.

something like this:

foreach(item i in arraylist)
    {
        foreach(item j in arraylist)
        {
            if(j.equals(i))
               arraylist.Remove(i);
        }
    }

However it is better to first sort your array and compare each item with the previous one, this way you don't have to iterate through the entire array for every item.

example with a sorted arraylist:

arraylist.Sort();

for (int i=1; i <= arraylist.Count-1; i++)
    {
       if(arraylist *== arraylist[i-1])*
 *{*
 *arraylist.Remove(i);*
 *}*
 *}*
*```*
*<p>I hope this helps ;)</p>*

I know this has been bumped by the bot from ages ago, but what Yoerick did is wrong, as Helpmepls123 found out. You can't remove an element in the middle of a foreach loop.

Either use 2 for statements and when you remove an element subtract 1 from iterator or store index of element you want removed in a buffer array then iterate through the buffer array removing the elements