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

  

posted @ 2015-12-14 17:47  N1900  阅读(359)  评论(0编辑  收藏  举报