主要讲解
1 、集合:
1.1 ArrayList
1.2 HashTable
2、泛型集合:
2.0 泛型 <t>
2.1 List<T>
2.2Dictionary<K,V>
2.3、泛型总结
ArrayList 非常有用的集合,有人称它为动态数组列表,是可以非常值观动态维护的,数组的容量是固定的,也可以根据需要自动扩展,它还提供了访问、删除、新增元素的操作;
ArrayList在System.Collections命名空间下,
例子:
using System.Collections;
ArrayList myList= new ArrayList();
ArrayList myList= new ArrayList(5);
注意:声明的时候必须初始化
myList.Add(Object obj); //增加一个元素
myList.Count(); //数组个数
objct obj = myList[index]; // 取出来是Object类型的 需要拆箱,转换成你存进去的数据(不要转哈 你看就行了)
例如:string str = (string)myList[index]; //前提是你知道里面是什么类型的,不然这样转换有错误建议 myList[index] as string,等很多方法;
//删除数据的3个方法
RemoveAt(int index); //根据索引删除
Remove(object obj); //根据你存储的对象删除
Clear(); //删除集合中所有的元素; 经常用此方法
//遍历集合 如果你支持3.0DLL你可以用LINQ遍历
ArrayList myList= new ArrayList(5);
myList.add(“a”);
myList.add(“b”);
myList.add(“c”);(不要转哈 你看就行了)
明天继续..