#region Dictionary  泛型集合,动态修改查询、查询和排序
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("北京", "1");
dic.Add("山西", "2");
dic.Add("深圳", "3"); if (!dic.ContainsKey("山西"))
{
dic.Add("山西", "5");
}
foreach (KeyValuePair<string, string> item in dic)
{
Console.WriteLine("Key:{0},Value{1}", item.Key, item.Value);
}
//排序遍历
var result = from d in dic orderby d.Key select d;
foreach (KeyValuePair<string, string> item in result)
{
Console.WriteLine("Key:{0},Value{1}", item.Key, item.Value);
}
#endregion

Arrary:

  #region Arrary 创建固定长度的数组
string[] str = { "1", "2", "3" };
int[] i = { 1, 2, 3, 4 };
//取数
string[] arr = new string[3];
arr[0] = "山西";
arr[1] = "广州";
arr[2] = "上海";
Console.WriteLine("{0}",arr.Length);
#endregion

ArrayList:

  #region  ArrayList 允许动态增加,移除元素,排序、反转数组  using System.Collections;

            ArrayList arraylist = new ArrayList();
arraylist.Add("山西");
arraylist.Add("北京");
Console.WriteLine("长度{0}",arraylist.Count); arraylist.Remove("北京");
arraylist.RemoveAt(1); //反转
arraylist.Reverse();
//排序
arraylist.Sort();
foreach (string s in arraylist)
{
Console.WriteLine(s);
} //允许创建元素为类实例的泛型数组
ArrayList arrList = new ArrayList();
arrList.Add(new Person(1, "1"));
foreach (Person item in arrList)
{
Console.WriteLine("item.Id:{0},item.Name:{1}",item.ID,item.Name);
} #endregion

List:

  #region  List  创建泛型集合,动态增加、排序、反转 using System.Collections.Generic;
List<Person> lists = new List<Person>();
lists.Add(new Person(1, "2"));
foreach (Person item in lists)
{
Console.WriteLine("item.Id:{0},item.Name:{1}", item.ID, item.Name);
}
#endregion

C#数组 List、Dictionary 、Arrary、ArrayList的更多相关文章

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

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

  2. C#数组,List,Dictionary的相互转换

    本篇文章会向大家实例讲述以下内容: 将数组转换为List 将List转换为数组 将数组转换为Dictionary 将Dictionary 转换为数组 将List转换为Dictionary 将Dicti ...

  3. 数组、List和ArrayList的区别

    有些知识点可能平时一直在使用,不过实际开发中我们可能只是知其然不知其所以然,所以经常的总结会对我们的提高和进步有很大的帮助,这里记录自己在工作之余的问题,持续更新,欢迎高手斧正. 数组.List和Ar ...

  4. C#重的数组、集合(ArrayList)、泛型集合(list<T>)三者比较及扩展延伸……

    本来我只想总结下数组.集合(ArrayList).泛型集合(list<T>)三者的比较的,可以一写下来要扩展的知识点有点多了,只能写一个小的知识点列表了如下: 1.数组.集合(ArrayL ...

  5. JAVA 基本数据结构--数组、链表、ArrayList、Linkedlist、hashmap、hashtab等

    概要 线性表是一种线性结构,它是具有相同类型的n(n≥0)个数据元素组成的有限序列.本章先介绍线性表的几个基本组成部分:数组.单向链表.双向链表:随后给出双向链表的C.C++和Java三种语言的实现. ...

  6. C#数组,List,Dictionary,IQueryable,IEnumerable的相互转换

    本篇文章会向大家实例讲述以下内容: 将数组转换为List 将List转换为数组 将数组转换为Dictionary 将Dictionary 转换为数组 将List转换为Dictionary 将Dicti ...

  7. 一个Json、数组、Dictionary转换和数组对比的C#实例

    最近做了一个程序,里面一段代码用到Json.数组.Dictionary转换和数组对比的一些知识,虽然在实际碰到类似问题时候有更好的方法,但这就当是一次基础知识的回顾,现在分享一下. 先介绍下要实现的业 ...

  8. Collection集合重难点梳理,增强for注意事项和三种遍历的应用场景,栈和队列特点,数组和链表特点,ArrayList源码解析, LinkedList-源码解析

    重难点梳理 使用到的新单词: 1.collection[kəˈlekʃn] 聚集 2.empty[ˈempti] 空的 3.clear[klɪə(r)] 清除 4.iterator 迭代器 学习目标: ...

  9. Hastable和Dictionary以及ArrayList和(List,LinkedList,数组)的区别

    Hastable和Dictionary的区别:(键值对) 1:单线程程序中推荐使用 Dictionary, 有泛型优势, 且读取速度较快, 容量利用更充分. 2:多线程程序中推荐使用 Hashtabl ...

  10. C#中Dictionary、ArrayList、Hashtable和Array的区别

    IDictionary接口是所有字典类集合的基本接口,该接口与ICollection,IEnumerable接口是所有非泛型类集合的最基本的接口 IEnumerable接口用于公开枚举数,该枚举数支持 ...

随机推荐

  1. DELPHI动态创建窗体

    //第一种方式 procedure TForm1.btn1Click(Sender: TObject); begin With TForm2.Create(Application) do Try Sh ...

  2. Java 策略模式(Strategy)

    创建一个能够根据所传递的参数对象的不同而具有不同行为的方法 要执行的算法固定不变,封装到一个类(Context)中 策略就是传递进去的参数对象,它包含执行代码 策略接口 /** * 策略接口 */ p ...

  3. 点分治&动态点分治小结

    (写篇博客证明自己还活着×2) 转载请注明原文地址:http://www.cnblogs.com/LadyLex/p/8006488.html 有的时候,我们会发现这样一类题:它长得很像一个$O(n) ...

  4. 标记,上传并下载自己创建的镜像 image

    1. 首先使用 docker images 查看已有镜像: 2. 获得 docker-whale 的 IMAGE ID,然后为 docker-whale 镜像 image 打上标签 Tag.使用命令: ...

  5. CODE FESTIVAL 2017 qual A 题解

    补一发A的题解. A - Snuke's favorite YAKINIKU 题意: 输入字符串S,如果以YAKI开头输出Yes,否则输出No. #include<bits/stdc++.h&g ...

  6. 神奇:java中float,double,int的值比较运算

    float x = 302.01f;    System.out.println(x == 302.01); //false  System.out.println(x == 302.01f); // ...

  7. string::replace

    #include <string> #include <cctype> #include <algorithm> #include <iostream> ...

  8. 命令行 设置redis 时间

    > set name jack OK > expire jack (integer) > ttl jack (integer) - > expire name (integer ...

  9. Codeforces 666 B. World Tour

    http://codeforces.com/problemset/problem/666/B 题意: 给定一张边权均为1的有向图,求四个不同的点A,B,C,D,使得dis[A][B]+dis[B][C ...

  10. mysql复杂查询(一)

    所谓复杂查询,指涉及多个表.具有嵌套等复杂结构的查询.这里简要介绍典型的几种复杂查询格式. 一.连接查询 连接是区别关系与非关系系统的最重要的标志.通过连接运算符可以实现多个表查询.连接查询主要包括内 ...