C# Dictionary的使用實例代碼
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幾種遍歷的實現(xiàn)代碼
- C# Hashtable/Dictionary寫入和讀取對比詳解
- C#中查找Dictionary中重復(fù)值的方法
- C#探秘系列(一)——ToDictionary,ToLookup
- C#泛型Dictionary的用法實例詳解
- C#中Dictionary的作用及用法講解
- C#泛型集合Dictionary<K,V>的使用方法
- C#針對xml文件轉(zhuǎn)化Dictionary的方法
- C#中Dictionary類使用實例
- C#實現(xiàn)自定義Dictionary類實例
- C#中查找Dictionary中的重復(fù)值的方法
- C#中Dictionary泛型集合7種常見的用法
相關(guān)文章
WinForm自定義函數(shù)FindControl實現(xiàn)按名稱查找控件
這篇文章主要介紹了WinForm自定義函數(shù)FindControl實現(xiàn)按名稱查找控件,需要的朋友可以參考下2014-08-08

