国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C# Dictionary的使用實例代碼

2020-01-24 03:29:20
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

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"));
            }
        }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 佛坪县| 澳门| 张北县| 九江市| 许昌县| 清水河县| 哈密市| 当涂县| 峡江县| 乐都县| 洪雅县| 四川省| 米脂县| 溧阳市| 肇源县| 合作市| 黑龙江省| 鄂尔多斯市| 自贡市| 田阳县| 易门县| 镇雄县| 合山市| 新野县| 临高县| 西华县| 北海市| 西宁市| 江津市| 新蔡县| 墨玉县| 富裕县| 浦北县| 普陀区| 安西县| 柳河县| 高密市| 陵川县| 云林县| 平果县| 普陀区|