list 交换位置扩展

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;
        }

  

原文地址:https://www.cnblogs.com/Zoes/p/5045958.html