手机
当前位置:查字典教程网 >编程开发 >C#教程 >C# Dictionary的使用实例代码
C# Dictionary的使用实例代码
摘要:复制代码代码如下:classDirctonary{publicvoidDictionaryGet(){DictionaryproductLi...

复制代码 代码如下:

class Dirctonary

{

public void DictionaryGet()

{

Dictionary<int, string> productList = new System.Collections.Generic.Dictionary<int, string>();

productList.Add(1, "ProductionOne");

productList.Add(2, "ProductionTwo");

foreach (KeyValuePair<int, string> production in productList)

{

MessageBox.Show(string.Format("{0},{1}", production.Key, production.Value));

}

//MessageBox.Show(productList.Count.ToString());

//MessageBox.Show(productList[1].ToString());

Dictionary<int, string>.KeyCollection keys = productList.Keys;

foreach (var item in keys)

{

MessageBox.Show(item.ToString());

}

Dictionary<int, string>.ValueCollection collection = productList.Values;

foreach (var item in collection)

{

MessageBox.Show(string.Format("{0}", item));

}

//productList.Remove(1);

//productList.Clear();

MessageBox.Show("判断是否包含键值对中的键为”1“的值");

if (productList.ContainsKey(1))

{

MessageBox.Show(productList[1]);

}

MessageBox.Show("判断是否包含键值对中的值为”ProductionTwo“的值");

if (productList.ContainsValue("ProductionTwo"))

{

MessageBox.Show(string.Format("{0}", "this really exists"));

}

}

【C# Dictionary的使用实例代码】相关文章:

C# 注册表 操作实现代码

C# TreeView控件使用代码

C# WORD操作实现代码

C#绝对路径拼接相对路径的实例代码

c# 调用.bat文件的实现代码

C#打印出正等腰三角形实例代码

C#数据结构之循环链表的实例代码

C#索引器简单实例代码

C# 手动/自动保存图片的实例代码

C# 实现简单打印的实例代码

精品推荐
分类导航