删除数组中重复的元素(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;

}

原文地址:https://www.cnblogs.com/matthew228/p/1827077.html