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

首頁 > 編程 > .NET > 正文

ASP.NET中Dictionary基本用法實例分析

2024-07-10 12:46:51
字體:
來源:轉載
供稿:網友

本文實例講述了ASP.NET中Dictionary基本用法。,具體如下:

//Dictionary位于System.Collections.Generic命名空間之下/* * 使用Dictionary之前必須引用System.Collections.Generic命名空間; * 使用Dictionary時必須聲明其鍵和值的數據類型(可以為任意類型); *///聲明實例化Dictionary為dicSystem.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),并返回其值dicStrstring 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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平遥县| 栾川县| 木兰县| 邢台市| 乐业县| 新安县| 酉阳| 长海县| 柘荣县| 遵化市| 高淳县| 沈阳市| 卢龙县| 名山县| 疏勒县| 常德市| 丰县| 河津市| 丹江口市| 沙洋县| 通河县| 安远县| 井研县| 综艺| 方正县| 潜山县| 罗江县| 麟游县| 林芝县| 望谟县| 防城港市| 墨竹工卡县| 西贡区| 平潭县| 霍林郭勒市| 江孜县| 舒城县| 宝丰县| 凤庆县| 和龙市| 新龙县|