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"));
}
}
相關文章
Parallel.For循環(huán)與普通for循環(huán)的性能比較
這篇文章介紹了Parallel.For循環(huán)與普通for循環(huán)的性能比較,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-04-04
C#實現(xiàn)數(shù)組元素的數(shù)據(jù)類型轉換方法詳解
這篇文章主要為大家介紹了C#中一維數(shù)組如何快速實現(xiàn)數(shù)組元素的數(shù)據(jù)類型的轉換,文中的示例代碼講解詳細,感興趣的小伙伴可以了解一下2022-04-04
C#基于Twain協(xié)議調用掃描儀,設置多圖像輸出模式(Multi image output)
這篇文章主要介紹了C#基于Twain協(xié)議調用掃描儀,設置多圖像輸出模式(Multi image output)的方法,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下2021-01-01
C#中圖片旋轉和翻轉(RotateFlipType)用法分析
這篇文章主要介紹了C#中圖片旋轉和翻轉(RotateFlipType)用法,實例分析了C#圖片旋轉及翻轉Image.RotateFlip方法屬性的常用設置技巧,需要的朋友可以參考下2015-06-06

