ASP.NET Dictionary 的基本用法示例介绍

内容摘要
复制代码 代码如下: Dictionary<string, string> o_Dic = new Dictionary<string, string>(); //添加元素 o_Dic.Add("01", "aaa"); o_Dic.Add("02","bbb"); //判断某个key
文章正文

复制代码 代码如下:

Dictionary<string, string> o_Dic = new Dictionary<string, string>();
//添加元素
o_Dic.Add("01", "aaa");
o_Dic.Add("02","bbb");
//判断某个key是否存在
if (!o_Dic.ContainsKey("03"))
{
o_Dic.Add("03", "ccc");
}
//移除某个
o_Dic.Remove("03");
//取某个的值
string a = o_Dic["02"];
//遍歷
foreach (KeyValuePair<string, string> kvp in o_Dic)
{
Response.Write(kvp.Key + "," + kvp.Value);
}
//遍歷key
foreach (string s in o_Dic.Keys) { }
//遍歷value
foreach (string s in o_Dic.Values) { }


代码注释

作者:喵哥笔记

IDC笔记

学的不仅是技术,更是梦想!