濮阳杆衣贸易有限公司

主頁 > 知識庫 > ASP.NET中Dictionary基本用法實例分析

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

熱門標(biāo)簽:400電話唐山辦理 電話機器人鑰匙扣 旅游地圖標(biāo)注線路 電銷外呼系統(tǒng)是違法的嗎 漯河外呼調(diào)研線路 地圖標(biāo)注位置怎么弄圖 電銷專用外呼線路 廣西房產(chǎn)智能外呼系統(tǒng)推薦 威力最大的電銷機器人

本文實例講述了ASP.NET中Dictionary基本用法。分享給大家供大家參考,具體如下:

//Dictionary位于System.Collections.Generic命名空間之下
/*
 * 使用Dictionary之前必須引用System.Collections.Generic命名空間;
 * 使用Dictionary時必須聲明其鍵和值的數(shù)據(jù)類型(可以為任意類型);
 */
//聲明實例化Dictionary為dic
System.Collections.Generic.Dictionaryint, string> dic = new System.Collections.Generic.Dictionaryint, string>();
//為dic添加鍵和值
dic.Add(100, "quber100");
dic.Add(200, "quber200");
//檢查是否存在300這個鍵
if (!dic.ContainsKey(300))
{
  //新增加300(鍵)和對應(yīng)的quber300(值)
  dic.Add(300, "quber300");
}
//移除dic鍵為300的項
dic.Remove(300);
//獲取dic鍵值對總數(shù)
int dicCount = dic.Count;
Response.Write("循環(huán)獲取dic中的鍵和值:br/>");
//循環(huán)獲取dic中的鍵和值
foreach (KeyValuePairint, string> keyDic in dic)
{
  Response.Write("key:" + keyDic.Key + ",value:" + keyDic.Value + "br/>");
}
Response.Write("hr/>br/>");
Response.Write("循環(huán)獲取dic中的鍵:br/>");
//循環(huán)獲取dic中的鍵
Dictionaryint, string>.KeyCollection keyDics = dic.Keys;
foreach (int iKey in keyDics)
{
  Response.Write("key:" + iKey + "br/>");
}
Response.Write("hr/>br/>");
Response.Write("另一種方法循環(huán)獲取dic中的鍵:br/>");
//循環(huán)獲取dic中的鍵
foreach (int iKey in dic.Keys)
{
  Response.Write("key:" + iKey + "br/>");
}
Response.Write("hr/>br/>");
Response.Write("循環(huán)獲取dic中的值:br/>");
//循環(huán)獲取dic中的值
Dictionaryint, string>.ValueCollection valueDics = dic.Values;
foreach (string strValue in valueDics)
{
  Response.Write("value:" + strValue + "br/>");
}
Response.Write("hr/>br/>");
Response.Write("另一種方法循環(huán)獲取dic中的值:br/>");
//循環(huán)獲取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/>");

更多關(guān)于asp.net相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《asp.net操作json技巧總結(jié)》、《asp.net字符串操作技巧匯總》、《asp.net操作XML技巧總結(jié)》、《asp.net文件操作技巧匯總》、《asp.net ajax技巧總結(jié)專題》及《asp.net緩存操作技巧總結(jié)》。

希望本文所述對大家asp.net程序設(shè)計有所幫助。

您可能感興趣的文章:
  • ASP.NET Dictionary 的基本用法示例介紹
  • C#實現(xiàn)自定義Dictionary類實例
  • C#針對xml文件轉(zhuǎn)化Dictionary的方法
  • C#泛型集合DictionaryK,V>的使用方法
  • C#中Dictionary的作用及用法講解
  • C#泛型Dictionary的用法實例詳解
  • C#探秘系列(一)——ToDictionary,ToLookup
  • C#中查找Dictionary中重復(fù)值的方法
  • C# Hashtable/Dictionary寫入和讀取對比詳解
  • C#中Dictionary幾種遍歷的實現(xiàn)代碼

標(biāo)簽:無錫 欽州 湘西 綏化 試駕邀約 湖北 銅陵 焦作

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP.NET中Dictionary基本用法實例分析》,本文關(guān)鍵詞  ASP.NET,中,Dictionary,基本,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ASP.NET中Dictionary基本用法實例分析》相關(guān)的同類信息!
  • 本頁收集關(guān)于ASP.NET中Dictionary基本用法實例分析的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    鄂尔多斯市| 邓州市| 西峡县| 佛坪县| 西城区| 镇巴县| 宣恩县| 台中县| 浦东新区| 大名县| 临猗县| 石城县| 东明县| 新巴尔虎左旗| 马龙县| 蓝田县| 绥阳县| 镇远县| 西畴县| 集安市| 故城县| 天门市| 锡林郭勒盟| 洪湖市| 长武县| 靖安县| 德州市| 巴南区| 柳林县| 武陟县| 逊克县| 泰安市| 白水县| 灵山县| 越西县| 措美县| 赤峰市| 翁源县| 凤台县| 通海县| 公主岭市|