首页 > 其他 > 详细

List<>集合

时间:2017-02-11 13:31:36      阅读:148      评论:0      收藏:0      [点我收藏+]
 1             List<int> clist = new List<int>();
 2             clist.Add(0);
 3             clist.Add(2);
 4             clist.AddRange( new int []{3,4,5,6,7});//往集合中添加数组,最后该数组内的元素,转换成集合中的元素
 5             clist.RemoveAll(r=>r>5);//删除集合中大于5的元素
 6             clist.Remove(3);//删除集合中元素值为3的元素
 7             Console.WriteLine(clist.Count);//集合现在实际含有的数量
 8             Console.WriteLine(clist.Capacity);//集合可以容纳的数量
 9             clist.RemoveAt(2);//删除集合中索引为2的元素
10             clist.RemoveRange(1, 2);//删除集合中一定范围的元素
11             clist.Insert(1,200);//在集合中索引为1的位置插入int 200
12             clist.InsertRange(1,new int []{1,2,3});//在集合中索引为1的位置插入数组
13 
14             //集合-->数组
15             int[] nums = clist.ToArray();//集合转换成数组
16 
17             //数组-->集合
18             int[] mun1 = new int() { 1,2,3,4,5};
19             List<int> ilist = mun1.ToList();//数组转转换成集合

 

List<>集合

原文:http://www.cnblogs.com/wwz-wwz/p/6389003.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!