Thursday, April 5, 2007

Code to Remove duplicate values from ArrayList

arr ->ArrayList with multiple values ,some unique and some repeating ex. {1,2,3,1,2,4,5}

for(i=0;i < arr.Count-1;i++)
{
for(j=i+1;j < arr.Count;j++)
{
if(arr[i].Equals(arr[j]))
{
arr.RemoveAt(j);
j = j - 1;
}
}
}

On executing code above arr={1,2,3,4,5}

No comments: