c# Dictionary字典类如何使用
Dictionary<string, string> openWith = new Dictionary<string, string>();
//添加元素
openWith.Add("txt", "notepad.exe");
openWith.Add("bmp", "paint.exe");
openWith.Add("dib", "paint.exe");
openWith.Add("rtf", "wordpad.exe"); Console.WriteLine("For key = \"rtf\", value = {0}.", openWith["rtf"]);
//更改值
openWith["rtf"] = "winword.exe";
Console.WriteLine("For key = \"rtf\", value = {0}.", openWith["rtf"]); //遍历key
foreach (string key in openWith.Keys)
{
Console.WriteLine("Key = {0}", key);
}
//遍历value
foreach (string value in openWith.Values)
{
Console.WriteLine("value = {0}", value);
}
//遍历字典
foreach (KeyValuePair<string, string> kvp in openWith)
{
Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
}
Console.WriteLine("===============");
//删除元素
openWith.Remove("rtf");
//遍历字典
foreach (KeyValuePair<string, string> kvp in openWith)
{
Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
}
c# Dictionary字典类如何使用的更多相关文章
- C#中的Dictionary字典类介绍
Dictionary字典类介绍 必须包含名空间System.Collection.Generic Dictionary里面的每一个元素都是一个键值对(由二个元素组成:键和值) 键必须是 ...
- (转)C#中的Dictionary字典类介绍
关键字:C# Dictionary 字典 作者:txw1958原文:http://www.cnblogs.com/txw1958/archive/2012/11/07/csharp-dictionar ...
- C# Dictionary字典类介绍
说明 必须包含名空间System.Collection.Generic Dictionary里面的每一个元素都是一个键值对(由二个元素组成:键和值) 键必须是唯一的,而值不需要唯 ...
- .net中的Dictionary字典类的使用方法
//定义字典 Dictionary<string, string> d = new Dictionary<string, string>(); //添加字典的元素 ; i &l ...
- Dictionary字典类介绍
说明 必须包含名空间System.Collection.Generic Dictionary里面的每一个元素都是一个键值对(由二个元素组成:键和值) 键必须是唯一的,而值不 ...
- Dictionary字典类使用范例
原文发布时间为:2009-11-04 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Web.UI.WebControls;using System ...
- C#中的Dictionary字典类常用方法介绍
using System.Collections.Generic;//引用命名空间//Dictionary可以理解为散列集合 public class DictionaryTest { public ...
- C# Dictionary 字典
C#中的Dictionary字典类介绍 关键字:C# Dictionary 字典 作者:txw1958原文:http://www.cnblogs.com/txw1958/archive/2012/ ...
- Swift字典类
在Foundation框架中提供一种字典集合,它是由“键-值”对构成的集合.键集合不能重复,值集合没有特殊要求.键和值集合中的元素可以是任何对象,但是不能是nil.Foundation框架字典类也分为 ...
随机推荐
- Seaborn-05-Pairplot多变量图
转自:http://www.jianshu.com/p/6e18d21a4cad
- STL学习笔记(转,还是比较全的)
STL简介 1 概况 2 1.1 STL是什么 2 1.2 为什么我们需要学习STL 2 1.3 初识STL 2 1.4 STL 的组成 5 2 容器 6 2.1 基本容器——向量(vector) 6 ...
- 【Python】什么是闭包
文章转载自:点这里 在 Python 中很多教材都没有提及什么是闭包,但在定义一个 Decorator 时,就已经用到闭包了.如果不理解什么是闭包,则不可能清晰掌握Decorator 装饰器. 要形成 ...
- yum search 不好用时
用 yum provides */ eg :yum provides */pstack
- Kubernetes 1.5.3 部署
> kubernetes 1.5.3, 配置文档 # 1 初始化环境 ## 1.1 环境: | 节 点 | I P ||--------|-------------||no ...
- 008-对象—— 对象$this self parent 内存方式及使用方法讲解
<?php /** * */ /*class Web{ private $webname; private $weburl; function __construct($webname,$web ...
- mysql数据库基础知识和认识
mysql 创建一个用户 hail,密码 hail,指定一个数据库 haildb 给 hail mysql -u root -ppassworduse mysql;insert into user(h ...
- C++复习11.函数的高级特性
C++ 函数的高级特性 20131002 C++函数增加了重载(override), inline, const, virtual四种机制,重载和内联机制既可以用于全局函数,也可以用于类的成员函数.c ...
- ZOJ 3521 Fairy Wars oj错误题目,计算几何,尺取法,排序二叉树,并查集 难度:2
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3521 ATTENTION:如果用long long 减小误差,这道题只能用 ...
- LNMP的搭建与原理
常见的web框架结构:例如:lnmp和:ampL=LINUX N=NGINX A=APACHE P=php T=Tomcat lnmp的原理 在LNMP组合工作时,首先是用户通过浏览器输入域名请求Ng ...