ASP.NET 泛型类型 Dictionary操作
生活随笔
收集整理的這篇文章主要介紹了
ASP.NET 泛型类型 Dictionary操作
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
protected void Page_Load(object sender, EventArgs e){//泛型Dictionary Dictionary<string, string> dit = new Dictionary<string, string>();dit.Add("13", "張三");dit.Add("22", "李四");Response.Write("總數" + dit.Count + "<br/>");//字典數據總數 dit.Remove("13");//刪除一個鍵 if (!dit.ContainsKey("13")){dit.Add("13", "張三1");}//判讀如果不包含指定的鍵則添加 foreach (KeyValuePair<string, string> kvp in dit){Response.Write(kvp.Key);Response.Write("=====" + kvp.Value);Response.Write("<br/>");}//循環字典中數據
Dictionary<string, string>.KeyCollection ditkey = dit.Keys;foreach (string k in ditkey){Response.Write(k + "<br/>");}//循環字典數據的鍵
Dictionary<string, string>.ValueCollection ditvalue = dit.Values;foreach (var v in ditvalue){Response.Write(v + "<br/>");}//循環字典數據里的值 foreach (var ditk in dit.Keys){Response.Write(ditk + "<br/>");}//另一種獲取字典鍵的方法 string f = dit["13"];Response.Write(f);//根據鍵 獲取值 string s = string.Empty;if (dit.TryGetValue("13", out s)){Response.Write("<br/>找到");}else{Response.Write("<br/>未找到");}//查找鍵是否存在 //泛型List 類型 List<string> a = new List<string>();a.Add("aa");a.Add("bb");foreach (string b in a){Response.Write("<br/>" + b + "<br/>");}//泛型IList IList<string> Il = new List<string>();Il.Add("11");Il.Add("22");foreach (var i in Il){Response.Write(i + "<br/>");}}
轉載于:https://www.cnblogs.com/ytjjyy/archive/2012/04/17/2453362.html
總結
以上是生活随笔為你收集整理的ASP.NET 泛型类型 Dictionary操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2022年世界杯举办国家是哪个?
- 下一篇: 大话设计模式之设计模式遵循的七大原则