码迷,mamicode.com
首页 > Windows程序 > 详细

C# 中的集合(Array/ArrayList/List<T>/HashTable/Dictionary)

时间:2018-03-14 00:58:30      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:ring   bsp   格式   res   numbers   素数   contains   ber   类型   

C# 中的集合(Array/ArrayList/List<T>/HashTable/Dictionary)

int [] numbers = new int[5]; // 长度为5,元素类型为 int。
string[,] names = new string[5,4]; // 5*4 的二维数组
byte[][] scores = new byte[5][]; // 长度为 5 的数组,元素为 byte的数组,元素数组的长度未知。

不同的格式:
int[] numbers = new int[5];
int[] numbers2 = new []{100, 200, 300, 400, 500};
int[] numbers3 = {100, 200, 300, 400, 500};

 

System.Collections.ArrayList

ArrayList al = new ArrayList();

al.Add(5);

al.Add("Hello Tom");

System.Collections.Generic.List<T>

List<int> intList = new List<int>();

intList.Add(500);

intList.AddRange(new int[]{1,100};

intList.Insert(1, 1000);

cw(intList.Contains(100));

cw(intList.indexOf(10));

System.Collections.HashTable

HashTable ht = new HashTable();

ht.Add("name", "Tom");

ht.Add("age", 18);

System.Collections.Generic.Dictionary

Dictionary<string, string> dic = new Dictionary<string, string>();

dic.Add("name", "Tom");

dic.Add("age", "eighteen");

C# 中的集合(Array/ArrayList/List<T>/HashTable/Dictionary)

标签:ring   bsp   格式   res   numbers   素数   contains   ber   类型   

原文地址:https://www.cnblogs.com/cjm123/p/8564164.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!