public static List<T> Swap<T>(this List<T> list, int index1,int index2) { if(index1<0||index1>=list.Count) { throw new Exception("index1"); } if (index2 < 0 || index2 >= list.Count) { throw new Exception("index2"); } var temp = list[index1]; list[index1] = list[index2]; list[index2] = temp; return list; }
时间: 2024-10-24 22:27:29