您的位置:首页 > 编程语言 > ASP

ASP.NET Dictionary 的基本用法

2013-12-06 10:42 253 查看
Dictionary<string, string> o_Dic = new Dictionary<string, string>();
            //添加元素
            o_Dic.Add("01", "aaa");
            o_Dic.Add("02","bbb");
            //判斷某個key是否存在
            if (!o_Dic.ContainsKey("03")) 
            {
                o_Dic.Add("03", "ccc");
            }
            //移除某個
            o_Dic.Remove("03");
            //取某個的值
            string a = o_Dic["02"];
            //遍歷
            foreach (KeyValuePair<string, string> kvp in o_Dic) 
            {
                Response.Write(kvp.Key + "," + kvp.Value);
            }
            //遍歷key
            foreach (string s in o_Dic.Keys) { }
            //遍歷value
            foreach (string s in o_Dic.Values) { }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: