static void Main(string[] args) { //看到数组的第一反应应该是排序 int[] array = { 2,4,6,2,8,5,8,10}; //去掉数组中重复的项 //先排序 arrayAsc(array); List<int> list = array.ToList(); for (int i = 0; i < list.Count-1; i++) { if(list[i]== list[i+1]) list.RemoveAt(i+1); } for (int i = 0; i < list.Count - 1; i++) { Console.WriteLine(list[i]); } Console.ReadKey(); } /// <summary> /// 排序 /// </summary> /// <param name="array"></param> /// <returns></returns> private static void arrayAsc(int[] array) { int i, j, temp; for (i = 0; i < array.Length-1; i++) { for (j = i+1; j < array.Length; j++) { if (array[i] > array[j]) { temp = array[i]; array[i] = array[j]; array[j] = temp; } } } }
原文地址:https://www.cnblogs.com/pushYYL/p/10930718.html
时间: 2024-10-08 19:17:06