学用 ASP.Net 之 System.Collections.Specialized.CollectionsUtil 类
生活随笔
收集整理的這篇文章主要介紹了
学用 ASP.Net 之 System.Collections.Specialized.CollectionsUtil 类
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
通過 CollectionsUtil 創建或包裝的 "鍵/值對" 類(實現 IDictionary 的), 可以忽略 Key 的大小寫.
主要成員:
/* 靜態方法 */ CollectionsUtil.CreateCaseInsensitiveHashtable(); //建立或包裝 Hashtable 等, 可初始化容量 CollectionsUtil.CreateCaseInsensitiveSortedList(); //建立有序的哈希表 SortedList
創建忽略大小寫的 Hashtable:
protected void Button1_Click(object sender, EventArgs e) {Hashtable hash = CollectionsUtil.CreateCaseInsensitiveHashtable(); //這就建立了一個忽略大小寫的哈希表hash["KEY1"] = 123;int n = (int)hash["key1"]; //123TextBox1.Text = n.ToString();try { hash.Add("Key1", 456); }catch (Exception err) { Response.Write(err.Message); } //已添加項。字典中的關鍵字:“KEY1”所添加的關鍵字:“Key1” }
創建忽略大小寫的 SortedList:
protected void Button1_Click(object sender, EventArgs e) {SortedList sl = CollectionsUtil.CreateCaseInsensitiveSortedList(); //這就建立了一個忽略大小寫的 SortedListsl["KEY1"] = 123;TextBox1.Text = sl["key1"].ToString(); //123try { sl.Add("Key1", 456); }catch (Exception err) { Response.Write(err.Message); } //已添加項。字典中的關鍵字:“KEY1”所添加的關鍵字:“Key1” }
包裝一個 Hashtable 為忽略大小寫:
protected void Button1_Click(object sender, EventArgs e) {Hashtable hash = new Hashtable();hash.Add("KEY1", "aaa");hash.Add("KEY2", "bbb");hash.Add("KEY3", "ccc");bool b1 = hash.Contains("KEY1"); //Truebool b2 = hash.Contains("key1"); //Falsehash = CollectionsUtil.CreateCaseInsensitiveHashtable(hash);bool b3 = hash.Contains("key1"); //TrueTextBox1.Text = string.Concat(b1, "\n", b2, "\n", b3); }
總結
以上是生活随笔為你收集整理的学用 ASP.Net 之 System.Collections.Specialized.CollectionsUtil 类的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 参加MS CRM2011深度培训课程第二
- 下一篇: MS CRM 2011 RC中的新特性(