C# 常用数组集合

时间:2022-09-03 13:46:15

1.定义数组 并赋值

 int[] Qpum = { 1, 2, 3 };

 多维数  string[,] name={{"j","k"},{"a","s"}};

 数组的取值通过索引取值Qpnum[1]

 

2. 集合  常用方法 Add()   Remove()

C# 常用数组集合C# 常用数组集合
 ArrayList A = new ArrayList();
//值类型是object
A.Add("123");
A.Add(
1);
A.Add(
2);
A.Remove(
1);
集合

 

3. 泛型集合 实例化时指定要添加的类集合

C# 常用数组集合C# 常用数组集合
定义集合  
List
<string> Lt = new List<string>();
Lt.Add(
"name");
Lt.Add(
"kk");
Lt.Insert(
0, "age");
Lt.Remove(
"kk");
Lt[
0] //获取集合的值
泛型集合

4.哈希表

C# 常用数组集合C# 常用数组集合
  哈希表  值没有规定的类型  
增加值时 采用键值对方式
Hashtable ht
= new Hashtable();
ht.Add(
"1", "20");
ht.Add(
"2", "21");
哈希表

5. 字典类型

C# 常用数组集合C# 常用数组集合
指定了键值对类型  
Dictionary
<string, string> d = new Dictionary<string, string>();
d.Add(
"jerry","Newy");
字典类型