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};

names.GetLength(0); // 获得二维数组的横向长度

names.GetLength(1); // 获得二维数组的纵向长度。

 

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<TKey, TValue>

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

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

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

哈  居然有人留言了。

简单说一下区别吧。

1、数组(Array)和 其余四个的区别是【类型指定】【长度固定】,其余四个长度都可以不固定(也可以指定长度)。

2、ArrayList 和 List<T> 的区别是 List<T> 是【类型指定】的。

3、HashTable 和 Dictionary<Tkey, Tvalue> 的 区别和 2 中的一样。后者是【类型指定】的。

C# 中的集合(Array/ArrayList/List<T>/HashTable/Dictionary)的更多相关文章

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

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

  2. Java中的集合Map、HashMap、Hashtable、Properties、SortedMap、TreeMap、WeakHashMap、IdentityHashMap、EnumMap(五)

    Map Map用于保存具有映射关系的数据,因此Map集合里保存着两组值,一组值用于保存Map里的key,另一组值用于保存Map里的value,key和value都可以是任何引用类型的数据.Map的ke ...

  3. 类 Array Arraylist List Hashtable Dictionary

    总结C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue  我们用的比较多的非泛型集合类主要有 ArrayList类 和 HashT ...

  4. c#中Array,ArrayList 与List<T>的区别、共性与转换

    本文内容来自我写的开源电子书<WoW C#>,现在正在编写中,可以去WOW-Csharp/学习路径总结.md at master · sogeisetsu/WOW-Csharp (gith ...

  5. Java中list集合ArrayList 中contains包含的使用

    Java中list集合ArrayList 中contains包含的使用 https://blog.csdn.net/qq_38556611/article/details/78774690

  6. 【转载】C#中AddRange方法往ArrayList集合末尾添加另一个集合

    ArrayList集合是C#中的一个非泛型的集合类,是弱数据类型的集合类,可以使用ArrayList集合变量来存储集合元素信息,任何数据类型的变量都可加入到同一个ArrayList集合中,如果需要往一 ...

  7. C#中数组、集合(ArrayList)、泛型集合List<T>、字典(dictionary<TKey,TValue>)全面对比

    C#中数组.集合(ArrayList).泛型集合List<T>.字典(dictionary<TKey,TValue>)全面对比 为什么把这4个东西放在一起来说,因为c#中的这4 ...

  8. Java中的集合List、ArrayList、Vector、Stack(三)

    List接口 List集合代表一个有序集合,集合中每一个元素都有其对应的顺序索引.List集合容许使用重复元素,可以通过索引来访问指定位置的集合对象. ArrayList和Vector实现类 Arra ...

  9. 面试:在面试中关于List(ArrayList、LinkedList)集合会怎么问呢?你该如何回答呢?

    前言 在一开始基础面的时候,很多面试官可能会问List集合一些基础知识,比如: ArrayList默认大小是多少,是如何扩容的? ArrayList和LinkedList的底层数据结构是什么? Arr ...

随机推荐

  1. Ubuntu 利用 crontab 和 notify-send 定时发送桌面通知,提示该休息啦

    [经测试,每隔多少分钟执行并不像自己想象的一样] 比如:每隔50分钟执行一次提醒      */50 * * * * export DISPLAY=:0.0; notify-send -i /home ...

  2. .NET 4.0中的泛型逆变和协变

    转载自:http://www.cnblogs.com/Ninputer/archive/2008/11/22/generic_covariant.html:自己加了一些理解 随Visual Studi ...

  3. Windows平台下载Android源码(整理)

    Google官方下载源码使用的系统Ubuntu系统,不过现在我们需要在Windows系统中下载Android源码文件. 网站的地址是:https://android.googlesource.com/ ...

  4. Nginx+Django搭建

    本机环境介绍 虚拟机操作系统版本如下 [root@node1 ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) IP地址 ...

  5. EF6 学习笔记(二):操练 CRUD 增删改查

    EF6学习笔记总目录 ASP.NET MVC5 及 EF6 学习笔记 - (目录整理) 接上篇: EF6 学习笔记(一):Code First 方式生成数据库及初始化数据库实际操作 本篇原文链接: I ...

  6. three.js 一幅图片多个精灵

    https://blog.csdn.net/zhulx_sz/article/details/79105359 核心代码 // 把一幅外部图片中包含的5种精灵存入一个精灵材质数组 var sprite ...

  7. Kubernetes-2--安装部署

    kubernetes的部署方式: 1,kubeadm 2, 二进制安装包部署 条件准备: 1,关闭系统的swap分区 为什么要关闭swap分区,我还没有去看官方的说明,搜索到的答案是 kubernet ...

  8. OpenStack-Ocata版+CentOS7.6 云平台环境搭建 — 8.仪表盘 Dashboard(horizon)安装配置

    仪表盘Dashboard(horizon)是一个web接口,使得云平台管理员以及用户可以管理不同的Openstack资源以及服务.这个部署示例使用的是 Apache Web 服务器. 节点配置信息说明 ...

  9. 使用jedis连接redis

    1.导入jar包,添加pom依赖<dependency><groupId>redis.clients</groupId><artifactId>jedi ...

  10. Python函数——装饰器

    前言 给下面的函数加上运行时间 def fib(n): a, b = 0, 1 for i in range(n): print(b) a, b = b, a+b return b a = fib(5 ...