C# Dictionary的使用實(shí)例代碼
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("判斷是否包含鍵值對(duì)中的鍵為”1“的值");
if (productList.ContainsKey(1))
{
MessageBox.Show(productList[1]);
}
MessageBox.Show("判斷是否包含鍵值對(duì)中的值為”P(pán)roductionTwo“的值");
if (productList.ContainsValue("ProductionTwo"))
{
MessageBox.Show(string.Format("{0}", "this really exists"));
}
}
- C#中Dictionary幾種遍歷的實(shí)現(xiàn)代碼
- C# Hashtable/Dictionary寫(xiě)入和讀取對(duì)比詳解
- C#中查找Dictionary中重復(fù)值的方法
- C#探秘系列(一)——ToDictionary,ToLookup
- C#泛型Dictionary的用法實(shí)例詳解
- C#中Dictionary的作用及用法講解
- C#泛型集合Dictionary<K,V>的使用方法
- C#針對(duì)xml文件轉(zhuǎn)化Dictionary的方法
- C#中Dictionary類(lèi)使用實(shí)例
- C#實(shí)現(xiàn)自定義Dictionary類(lèi)實(shí)例
- C#中查找Dictionary中的重復(fù)值的方法
- C#中Dictionary泛型集合7種常見(jiàn)的用法
相關(guān)文章
C#多線(xiàn)程之線(xiàn)程同步WaitHandle
這篇文章介紹了C#多線(xiàn)程之線(xiàn)程同步WaitHandle的用法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-03-03winform實(shí)現(xiàn)限制及解除鼠標(biāo)移動(dòng)范圍的方法
這篇文章主要介紹了winform實(shí)現(xiàn)限制及解除鼠標(biāo)移動(dòng)范圍的方法,涉及C#控制WinForm鼠標(biāo)事件屬性的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09C# 中使用NModbus4通信庫(kù)執(zhí)行寫(xiě)操作
在C#中NModbus4庫(kù)提供了一個(gè)方便的方式來(lái)與支持Modbus協(xié)議的設(shè)備進(jìn)行交互,本文就來(lái)介紹了使用NModbus4通信庫(kù)執(zhí)行寫(xiě)操作,具有一定的參考價(jià)值,感興趣的可以了解一下2024-03-03Parallel.For循環(huán)與普通for循環(huán)的性能比較
這篇文章介紹了Parallel.For循環(huán)與普通for循環(huán)的性能比較,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04C#實(shí)現(xiàn)數(shù)組元素的數(shù)據(jù)類(lèi)型轉(zhuǎn)換方法詳解
這篇文章主要為大家介紹了C#中一維數(shù)組如何快速實(shí)現(xiàn)數(shù)組元素的數(shù)據(jù)類(lèi)型的轉(zhuǎn)換,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下2022-04-04C#基于Twain協(xié)議調(diào)用掃描儀,設(shè)置多圖像輸出模式(Multi image output)
這篇文章主要介紹了C#基于Twain協(xié)議調(diào)用掃描儀,設(shè)置多圖像輸出模式(Multi image output)的方法,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下2021-01-01C#中圖片旋轉(zhuǎn)和翻轉(zhuǎn)(RotateFlipType)用法分析
這篇文章主要介紹了C#中圖片旋轉(zhuǎn)和翻轉(zhuǎn)(RotateFlipType)用法,實(shí)例分析了C#圖片旋轉(zhuǎn)及翻轉(zhuǎn)Image.RotateFlip方法屬性的常用設(shè)置技巧,需要的朋友可以參考下2015-06-06