删除数组中重复的元素(C#实现)

public static int[] RemoveDuplicated(int [] testArray)

{

if (testArray.Length == 0)

{

return testArray;

}

List<int> result = new List<int>();

int i;

int j;

i = 1;

j = 0;

int temp = testArray[0];

result.Add(testArray[0]);

while (i < testArray.Length)

{

if(testArray[i]!= temp)

{

j++;

temp = testArray[i];

result.Add(temp);

}

i++;

}

int[] test = Array.ConvertAll<int, int>(result.ToArray(), new Converter<int, int>(Convert.ToInt32));

return test;

}

posted @ 2010-09-15 15:31  purplesun  阅读(1266)  评论(1编辑  收藏  举报