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

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");

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

时间: 2024-08-13 06:06:33

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

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

Map Map用于保存具有映射关系的数据,因此Map集合里保存着两组值,一组值用于保存Map里的key,另一组值用于保存Map里的value,key和value都可以是任何引用类型的数据.Map的key不容许重复,即同一个Map对象的任何两个key通过equals方法比较总是返回false. key和value之间存在单向一对一关系,即通过指定的key,总能找到唯一的.确定的value.从Map中取出数据时,只要给出指定的key,就可以取出对应的value. 如果把Map里的所有key放在一起看

Scala中的集合:Iterator、BitSet、Set、Map、Stack、Vector、List、Array

 5.   util包 5.1.     架构 http://www.scala-lang.org/docu/files/collections-api/collections.html The following figure shows all collections in package scala.collection. These are all high-level abstract classes or traits, which generally have mutable

【转载】C#中[],List,Array,ArrayList的区别及应用

本篇文章主要是对C#中[],List,Array,ArrayList的区别及应用进行了详细的介绍,需要的朋友可以过来参考下,希望对大家有所帮助 [] 是针对特定类型.固定长度的. List 是针对特定类型.任意长度的. Array 是针对任意类型.固定长度的. ArrayList 是针对任意类型.任意长度的. Array 和 ArrayList 是通过存储 object 实现任意类型的,所以使用时要转换.

C#中数组、集合(ArrayList)、泛型集合List&lt;T&gt;、字典(dictionary&lt;TKey,TValue&gt;)全面对比

为什么把这4个东西放在一起来说,因为c#中的这4个对象都是用来存储数据的集合--. 首先咱们把这4个对象都声明并实例化一下: //数组 string[] m_Str = new string[5]; //集合 ArrayList m_AList = new ArrayList(); //泛型集合 List<int> m_List = new List<int>(); //字典 Dictionary<int, string> m_Dt = new Dictionary&l

C#中的集合有几种?

C#中的集合有几种? Array ArrayList List<T> Stack<T> Queue<T> Dictionary<K,V> HashTable   集合,表示可以通过遍历每个元素来访问的一组对象(特别是可使用foreach循环访问) 一个集合包括多个元素,即有一个集合类对象和N个元素对象  因为任何集合类都实现了IEnumerable接口,所以任何集合类对象都有一个GetEnumerator()方法,该方法可以返回一个实现了 IEnumerat

Java集合类库 ArrayList 源码解析

集合类库是Java的一个重大突破,方便了我们对大数据的操作.其中 Arrays 和 Collections 工具类可以帮助我们快速操作集合类库.下面对Java集合类库的源码分析是基于jdk1.7的.今天我们来看看ArrayList的底层实现原理. ArrayList的继承结构图 继承自 AbstractList 抽象类,在上层是 AbstractCollection 抽象类,直接去 AbstractCollection 类去看看. AbstractCollection 类主要实现了 Collec

C#语言基础——集合(ArrayList集合)

集合及特殊集合 集合的基本信息: System.Collections 命名空间包含接口和类,这些接口和类定义各种对象(如列表.队列.位数组.哈希表和字典)的集合.System.Collections.Generic 命名空间包含定义泛型集合的接口和类,泛型集合允许用户创建强类型集合,它能提供比非泛型强类型集合更好的类型安全性和性能.ystem.Collections.Specialized 命名空间包含专用的和强类型的集合,例如,链接的列表词典.位向量以及只包含字符串的集合. 常用的集合为Ar

java中各种集合的用法和比较

一,java中各种集合的关系图 Collection       接口的接口     对象的集合 ├ List             子接口         按进入先后有序保存   可重复 │├ LinkedList    接口实现类     链表     插入删除   没有同步   线程不安全 │├ ArrayList     接口实现类      数组     随机访问   没有同步   线程不安全 │└ Vector        接口实现类       数组              

Java 集合(ArrayList)应用

JAVA集合 对象数组 集合类之ArrayList 学生管理系统 NO.one 对象数组 1.1 对象数组描述 A:基本类型的数组:存储的元素为基本类型 int[] arr={1,2,3,4} B:对象数组:存储的元素为引用类型 Student[] stus=new Student[3]; Student代表一个自定义类 Stus数组中stus[0],stus[1],stus[2]的元素数据类型为Student, 都可以指向一个Student对象 1.2 对象数组案例: 创建一个学生数组,存储三