源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

C# Dictionary的使用实例代码

  • 时间:2020-08-29 12:07 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:C# Dictionary的使用实例代码
[u]复制代码[/u] 代码如下:
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"));             }         }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部