1、字典定义并添加数据

            Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("a", "北京");
dic.Add("c", "上海");
dic.Add("b", "广州");
dic.Add("d", "深圳");

2、遍历字典项

            foreach (KeyValuePair<string, string> d in dic)
{
Console.WriteLine(d.Key + " " + d.Value);
}
            foreach (var itm in dic)
{
Console.WriteLine(itm.Key + " " + itm.Value);
}
            foreach (string s in dic.Keys)
{
Console.WriteLine(s + " " + dic[s]);
} foreach (string s in dic.Values)
{
Console.WriteLine(s);
}

3、字典排序并输出

            字典排序:List<KeyValuePair<string,string>> list = dic.OrderBy(r => r.Key).ToList<KeyValuePair<string, string>>();
       //dic =dic.OrderByDescending(r => r.Key).ToDictionary(r => r.Key, r => r.Value);
foreach (KeyValuePair<string, string> kv in list)
{
Console.WriteLine(kv.Key + " " + kv.Value);
}

C# Dictionary 应用的更多相关文章

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

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

  2. ASP.NET Aries JSAPI 文档说明:AR.DataGrid、AR.Dictionary

    AR.Global 文档 1:对象或属性: 名称 类型 说明 DG 对象 DataGrid操作对象 //datagrid集合,根据ID取出DataGrid对象,将Json当数组用. Items: ne ...

  3. WebAPI接口返回ArrayList包含Dictionary对象正确解析

    一.问题提出 为了减少流量,将key-value(键值对)直接输出到Dictionary<string, string>,接口返回结果如下: 其中{}里面内容如下: 上图显示600是键,4 ...

  4. Linq在Array,List,Dictionary中的应用

    Linq在Array,List,Dictionary中的应用 今天在实际工作中需要对array,list,dictionary进行排序,试一试linq,发现非常好用,代码如下: using Syste ...

  5. python之最强王者(8)——字典(dictionary)

    1.Python 字典(Dictionary) 字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包 ...

  6. Swift3 - String 字符串、Array 数组、Dictionary 字典的使用

    Swift相关知识,本随笔为 字符串.数组.字典的简单使用,有理解.使用错误的地方望能指正. ///************************************************** ...

  7. [LeetCode] Alien Dictionary 另类字典

    There is a new alien language which uses the latin alphabet. However, the order among letters are un ...

  8. Dictionary

    命名空间:System.Collections.Generic(程序集:mscorlib) Dictionary<TKey, TValue> 类   一般用法:通过key获取value,k ...

  9. 关于 Dictionary<string,string>,和List<T>在View的使用

    在MVC中Dictionary<string,string>如何应用到View页面中呢,例: <input type="text" name=key value= ...

  10. Dictionary Learning(字典学习、稀疏表示以及其他)

    第一部分 字典学习以及稀疏表示的概要 字典学习(Dictionary Learning)和稀疏表示(Sparse Representation)在学术界的正式称谓应该是稀疏字典学习(Sparse Di ...

随机推荐

  1. QT 5.1.1 for Android 开发环境搭建与配置【Windows 7】

    前言:本人操作系统为Windows7 64位,用的是32位的安装包,32位系统没有验证. 一.首先下载以下安装包,如果提供的链接失效请自行下载: (1) Android SDK (Windows 32 ...

  2. wdcp/wdlinux一键包的php5.3版本添加Zend.so 和Soap.so

    Wdcp 安装soap扩展 1.首先进入 soap模块的安装文件,wdcp安装包解压对应的php中有,如:/root/miloxi/lanmp/php-5.5.10/ext/soap 2.执行: (1 ...

  3. js的兼容性问题

    innerHTML和innerTEXT的使用问题 <html xmlns="http://www.w3.org/1999/xhtml"> <head> &l ...

  4. [算法导论]贪心算法(greedy algorithm)

    转载请注明出处:http://www.cnblogs.com/StartoverX/p/4611544.html 贪心算法在每一步都做出当时看起来最佳的选择.也就是说,它总是做出局部最优的选择,寄希望 ...

  5. app 测试点

    以下所有测试最后必须在真机上完整的执行1.安装.卸载测试 在真机上的以及通过91等第三方的安装与卸载 安装在手机上还是sd卡上 2.启动app测试3.升级测试 数字签名.升级覆盖安装.下载后手动覆盖安 ...

  6. 自己封装的HttpRequest,个人觉的比较HttpHelper好用

    新年开篇,忙归忙,还是要写点什么,不然越来越懒,分享我写的HttpTooler public delegate void RequestCompleted(object sender, string ...

  7. 2015年6月股灾永远载入A股史册

    之前很奇怪这次牛市行情的暴涨与暴跌,后来发现成交量是以往不可想象的,而这一切的源头就是融资融券,也就是杠杆. 杠杆的作用是无穷的,就像阿基米德说的那样“给我一个支点,我就能撬起地球”. 杠杆是个放大器 ...

  8. obj文件的连接问题以及tlib的基本用法

    1.基础研究 用tcc将程序编译为.obj文件. 这里也可以使用tcc -linclude run.c来将run.c文件编译成run.obj文件. 再用tcc对下面的程序进行编译链接,发现提示错误: ...

  9. QuerryRunner Tools

    package com.ydbg.gis.utils; import java.sql.SQLException; import java.util.List; import java.util.Ma ...

  10. BZOJ3564 信号增幅仪

    http://www.lydsy.com/JudgeOnline/problem.php?id=3564 思路:先旋转坐标系,再缩进x坐标,把椭圆变成圆,然后做最小圆覆盖. 还有,为什么用srand( ...