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ì)中的值為”ProductionTwo“的值");
if (productList.ContainsValue("ProductionTwo"))
{
MessageBox.Show(string.Format("{0}", "this really exists"));
}
}
- C#中Dictionary幾種遍歷的實(shí)現(xiàn)代碼
- C# Hashtable/Dictionary寫入和讀取對(duì)比詳解
- C#中查找Dictionary中重復(fù)值的方法
- C#探秘系列(一)——ToDictionary,ToLookup
- C#泛型Dictionary的用法實(shí)例詳解
- C#中Dictionary的作用及用法講解
- C#泛型集合Dictionary<K,V>的使用方法
- C#針對(duì)xml文件轉(zhuǎn)化Dictionary的方法
- C#中Dictionary類使用實(shí)例
- C#實(shí)現(xiàn)自定義Dictionary類實(shí)例
- C#中查找Dictionary中的重復(fù)值的方法
- C#中Dictionary泛型集合7種常見(jiàn)的用法
相關(guān)文章
C#實(shí)現(xiàn)獲得某個(gè)枚舉的所有名稱
這篇文章主要為大家詳細(xì)介紹了C#如何實(shí)現(xiàn)獲得某個(gè)枚舉的所有名稱,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,有需要的小伙伴可以參考一下2025-01-01
C#算法之無(wú)重復(fù)字符的最長(zhǎng)子串
這篇文章介紹了C#算法之無(wú)重復(fù)字符的最長(zhǎng)子串,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-01-01
WinForm自定義函數(shù)FindControl實(shí)現(xiàn)按名稱查找控件
這篇文章主要介紹了WinForm自定義函數(shù)FindControl實(shí)現(xiàn)按名稱查找控件,需要的朋友可以參考下2014-08-08
c#定時(shí)器和global實(shí)現(xiàn)自動(dòng)job示例
這篇文章主要介紹了c#定時(shí)器和global實(shí)現(xiàn)自動(dòng)job示例,大家參考使用吧2014-01-01
C#中GraphicsPath的Flatten方法用法實(shí)例
這篇文章主要介紹了C#中GraphicsPath的Flatten方法,實(shí)例分析了Flatten方法的相關(guān)使用技巧,需要的朋友可以參考下2015-06-06

