码迷,mamicode.com
首页 > 其他好文 > 详细

list 交换位置扩展

时间:2015-12-14 19:04:06      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

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

  

list 交换位置扩展

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!