无为清净楼资源网 Design By www.qnjia.com
本文实例讲述了ASP.NET中Dictionary基本用法。分享给大家供大家参考,具体如下:
//Dictionary位于System.Collections.Generic命名空间之下 /* * 使用Dictionary之前必须引用System.Collections.Generic命名空间; * 使用Dictionary时必须声明其键和值的数据类型(可以为任意类型); */ //声明实例化Dictionary为dic System.Collections.Generic.Dictionary<int, string> dic = new System.Collections.Generic.Dictionary<int, string>(); //为dic添加键和值 dic.Add(100, "quber100"); dic.Add(200, "quber200"); //检查是否存在300这个键 if (!dic.ContainsKey(300)) { //新增加300(键)和对应的quber300(值) dic.Add(300, "quber300"); } //移除dic键为300的项 dic.Remove(300); //获取dic键值对总数 int dicCount = dic.Count; Response.Write("循环获取dic中的键和值:<br/>"); //循环获取dic中的键和值 foreach (KeyValuePair<int, string> keyDic in dic) { Response.Write("key:" + keyDic.Key + ",value:" + keyDic.Value + "<br/>"); } Response.Write("<hr/><br/>"); Response.Write("循环获取dic中的键:<br/>"); //循环获取dic中的键 Dictionary<int, string>.KeyCollection keyDics = dic.Keys; foreach (int iKey in keyDics) { Response.Write("key:" + iKey + "<br/>"); } Response.Write("<hr/><br/>"); Response.Write("另一种方法循环获取dic中的键:<br/>"); //循环获取dic中的键 foreach (int iKey in dic.Keys) { Response.Write("key:" + iKey + "<br/>"); } Response.Write("<hr/><br/>"); Response.Write("循环获取dic中的值:<br/>"); //循环获取dic中的值 Dictionary<int, string>.ValueCollection valueDics = dic.Values; foreach (string strValue in valueDics) { Response.Write("value:" + strValue + "<br/>"); } Response.Write("<hr/><br/>"); Response.Write("另一种方法循环获取dic中的值:<br/>"); //循环获取dic中的值 foreach (string strValue in dic.Values) { Response.Write("value:" + strValue + "<br/>"); } Response.Write("<hr/><br/>"); Response.Write("获取dic中单个键和值:<br/>"); Response.Write("key:100,value:" + dic[100] + "<br/>"); Response.Write("<hr/><br/>"); Response.Write("检查dic中是否存在键(100),并返回其值dicStr:<br/>"); //检查dic中是否存在键(100),并返回其值dicStr string dicStr = string.Empty; if (dic.TryGetValue(100, out dicStr)) { Response.Write("OK"); } else { Response.Write("NO"); } Response.Write("<hr/><br/>");
更多关于asp.net相关内容感兴趣的读者可查看本站专题:《asp.net操作json技巧总结》、《asp.net字符串操作技巧汇总》、《asp.net操作XML技巧总结》、《asp.net文件操作技巧汇总》、《asp.net ajax技巧总结专题》及《asp.net缓存操作技巧总结》。
希望本文所述对大家asp.net程序设计有所帮助。
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月27日
2024年09月27日
- 李恕权.2003-回·20年全精选2CD【SONY】【WAV+CUE】
- 群星《你就在我身边 电影原声专辑》[320K/MP3][26.68MB]
- 群星《你就在我身边 电影原声专辑》[FLAC/分轨][70.27MB]
- 班得瑞原装进口《20周年精选集》1CD[APE/CUE分轨][303MB]
- 群星.2009-NOON.D.广东.2CD【新世纪】【WAV+CUE】
- 洪卓立.2012-GROWN.UP【英皇娱乐】【WAV+CUE】
- 梁静茹.2007-崇拜【相信音乐】【WAV+CUE】
- 金佩姗.1997-喜新恋旧【现代派】【WAV+CUE】
- 梁静茹.2007-崇拜【相信音乐】【WAV+CUE】
- 陈晓东.1997-在乎你感受(EP)【宝丽金】【WAV+CUE】
- 纯音入心系列纯音乐《云水禅心 - 佛曲古筝礼赞1-2》1CD[MP3][190MB]
- 纯音入心系列纯音乐《精心传神-古筝》1CD[MP3][363.1MB]
- 纯音入心系列纯音乐《琴瑟古风之古筝精选曲》1CD[MP3][354.1MB]
- 陈晓东.1997-在乎你感受(EP)【宝丽金】【WAV+CUE】
- 黄凯芹.1990-给你留念(2024环球MQA-UHQCD限量版)【环球】【WAV+CUE】