首页 > 其他 > 详细

list 交换位置扩展

时间:2015-12-14 19:02:50      阅读:215      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!