Dictionary<string, string>是一个泛型

他本身有集合的功能有时候可以把它看成数组

他的结构是这样的:Dictionary<[key], [value]>

他的特点是存入对象是需要与[key]值一一对应的存入该泛型

通过某一个一定的[key]去找到对应的值

举个例子:

//实例化对象

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

//对象打点添加

dic.Add(1, "one");

dic.Add(2, "two");

dic.Add(3, "one");

//提取元素的方法

string a = dic[1];

string b = dic[2];

string c = dic[3];

//1、2、3是键,分别对应“one”“two”“one”

//上面代码中分别把值赋给了a,b,c

//注意,键相当于找到对应值的唯一标识,所以不能重复

//但是值可以重复

如果你还看不懂我最后给你举一个通俗的例子

有一缸米,你想在在每一粒上都刻上标记,不重复,相当于“键”当你找的时候一一对应不会找错,这就是这个泛型的键的-作用,而米可以一样,我的意思你明白了吧?

-------------------------------------------------------------------------

c# 对dictionary类进行排序用什么接口实现

如果使用.Net Framework 3.5的话,事情就很简单了。呵呵。

如果不是的话,还是自己写排序吧。

using System;

using System.Collections.Generic;

using System.Text;

using System.Linq;

namespace DictionarySorting

{

class Program

{

static void Main(string[] args)

{

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

dic.Add(1, "HaHa");

dic.Add(5, "HoHo");

dic.Add(3, "HeHe");

dic.Add(2, "HiHi");

dic.Add(4, "HuHu");

var result = from pair in dic orderby pair.Key select pair;

foreach (KeyValuePair<int, string> pair in result)

{

Console.WriteLine("Key:{0}, Value:{1}", pair.Key, pair.Value);

}

Console.ReadKey();

}

}

}

【执行结果】

Key:1, Value:HaHa

Key:2, Value:HiHi

Key:3, Value:HeHe

Key:4, Value:HuHu

Key:5, Value:HoHo

最新文章

  1. 【MongoDB初识】-结合C#简单使用,驱动2.x
  2. php怎么获取mac地址?
  3. 内存管理_JAVA内存管理
  4. [CareerCup] 8.9 An In-memory File System 内存文件系统
  5. redis提示Could not get a resource from the pool(jedis连接池配置)
  6. PHP设计模式之装饰者模式
  7. struts 中 s:iterator 使用注意事项
  8. iOS序列化与反序列化
  9. uva 10934 Dropping water balloons(转载)
  10. CachedRowSet的用法
  11. tooltip 鼠标移动上去出现图片或文字与title大同小异
  12. GCJ Round 1C 2009 Problem C. Bribe the Prisoners
  13. 使用Hbuilder手机debug
  14. list实现大整数加法
  15. Python手记(二)
  16. Xamarin.Android 使用SoundPool进行音频播放
  17. Day16作业及默写
  18. AForge.NET简介
  19. OneZero第二周第二次站立会议(2016.3.29)
  20. Steady Cow Assignment POJ - 3189 (最大流+匹配)

热门文章

  1. mysql5.7.18-winx64安装
  2. .c和.h文件的区别
  3. PYNQ上手笔记 | ① 启动Pynq
  4. html的一些基本语法学习与实战
  5. JDK1.8源码分析01之学习建议(可以延伸其他源码学习)
  6. 又拍云叶靖:OpenResty 在又拍云存储中的应用
  7. Python Iterator and Generator
  8. Spring 2017 Assignments2
  9. java后端开发面经 数据库相关
  10. HTTP与HTTPS之面试必备