#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. 【跨域】jsonp跨域实现方法

    封装原生jsonp: 以跨域调取豆瓣电影最热榜单为例: function $jsonp(url,data,callback){ var funcName = 'jsonp_cb' + Math.ran ...

  2. JIRA状态为任务结束,但是解决结果为未解决相关配置

    1.JIRA状态为任务结束,但是解决结果为未解决,如下图所示: 2.在工作流->界面->结果处理中进行解决结果的配置(首先确保界面配置中有“解决结果”字段). 3.点击“结果处理”,进行结 ...

  3. sniffer 和 debug flow

    sniffer 和 debug flow sniffer 和 debug flow 复制模板,直接修改IP即可使用: diagnose sys session filter clear diagnos ...

  4. oracle 获取当前用户下的所有表名与字段信息

     select *from user_col_commentswhere substr(table_name,1,3)<>'BIN' 

  5. Dubbo 生态添新兵,Dubbo Admin 发布 v0.1

    为了提升 Dubbo 里程碑版本2.7.0的使用体验,我们于去年年中启动了 Dubbo Admin 的重构计划,并作为Dubbo生态的子项目,于近期发布了v0.1,重构后的项目在结构上的变化如下: 将 ...

  6. 【BZOJ2563】阿狸和桃子的游戏(贪心)

    [BZOJ2563]阿狸和桃子的游戏(贪心) 题面 BZOJ 题解 边权平均分给两个点就好了. #include<iostream> #include<cstdio> #inc ...

  7. 【BZOJ3489】A simple rmq problem(KD-Tree)

    [BZOJ3489]A simple rmq problem(KD-Tree) 题面 BZOJ 题解 直接做肯定不好做,首先我们知道我们是一个二维平面数点,但是限制区间只能出现一次很不好办,那么我们给 ...

  8. 【NOIP 2018】填数游戏(思考与推导)

    题目链接 这道题讲道理还是不错的,因为你需要不断挖掘其中的性质来帮助解题.可惜数据范围开在这里让考试时的我很慌,勉强也就写了$65$分就没了.回忆在考场上,思路是没有错的,就是发掘不够深入,思路还不够 ...

  9. python之旅:网络编程

    一 客户端/服务器架构 1.硬件C/S架构(打印机) 2.软件C/S架构 互联网中处处是C/S架构 如黄色网站是服务端,你的浏览器是客户端(B/S架构也是C/S架构的一种) 腾讯作为服务端为你提供视频 ...

  10. redis 中用正则找key

    获取 redis 中所有的 key 可用使用 *. redis 127.0.0.1:6379> KEYS * 1) "w3c3" 2) "w3c1" 3) ...