国产探花免费观看_亚洲丰满少妇自慰呻吟_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"));
            }
        }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 罗田县| 晴隆县| 乌海市| 泗阳县| 八宿县| 台北县| 江油市| 水城县| 淳化县| 泉州市| 商南县| 鹤岗市| 柘荣县| 蒙山县| 河北省| 仁布县| 武清区| 石林| 晋中市| 蒙自县| 六盘水市| 含山县| 谷城县| 巴塘县| 晴隆县| 黄大仙区| 南投县| 明光市| 昭平县| 乌拉特后旗| 荥经县| 仙桃市| 蕉岭县| 宣武区| 怀化市| 南昌市| 南宫市| 尤溪县| 顺平县| 翁源县| 巴里|