泛型集合是指List<>()
List<>()的一些常用方法:
- List<int> list=new List<int>( );//创建泛型集合对象
- list.Add( )
- list.AddRange( )
- list.AddRange(new int[ ] {1,2,3,4,5,6})
- list.Insert(index, 555);//在index位置添加一个元素
- list.Remove( )//删除一个值
- list.RemoveAt(index)删除下标为index的元素
- list.RemoveRange(index, count)//从index开始,删除count个元素
- list.Sort()//升序
- list.Reverse()//顺序反转
- list.ToArray( )//List泛型集合可以转换为数组
- list.Clear();//清除元素
- list.Min();//找到最小值
- list.Max();//找到最大值
- list.IndexOf();//搜索元素所在索引
- 值得注意的是:①list.Remove()删除元素把坑和元素都删除了,而.Clear()只会清除元素,但是坑还在,那就是说,会留下空值。②list.Add(?)有需要注意的,附上地址,这篇写得挺好