最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2016年08月04日 10:09:28   作者:Quber  
這篇文章主要介紹了ASP.NET中Dictionary基本用法,結合實例形式分析了Dictionary的基本功能、使用步驟與相關操作技巧,需要的朋友可以參考下

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

//Dictionary位于System.Collections.Generic命名空間之下
/*
 * 使用Dictionary之前必須引用System.Collections.Generic命名空間;
 * 使用Dictionary時必須聲明其鍵和值的數(shù)據(jù)類型(可以為任意類型);
 */
//聲明實例化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鍵值對總數(shù)
int dicCount = dic.Count;
Response.Write("循環(huán)獲取dic中的鍵和值:<br/>");
//循環(huán)獲取dic中的鍵和值
foreach (KeyValuePair<int, 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中的鍵
Dictionary<int, 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中的值
Dictionary<int, 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/>");

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

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

相關文章

最新評論

新乡县| 东丰县| 洪洞县| 望都县| 柘荣县| 香格里拉县| 六枝特区| 荣昌县| 吴忠市| 泾川县| 田林县| 麻阳| 吴江市| 桐城市| 衡水市| 定边县| 孟津县| 宁远县| 如皋市| 札达县| 宁德市| 漾濞| 东山县| 陈巴尔虎旗| 德庆县| 光泽县| 隆德县| 梁山县| 南宫市| 长子县| 山东省| 平湖市| 图木舒克市| 周口市| 手游| 大田县| 临猗县| 常宁市| 衡阳县| 江安县| 舞阳县|