/* 静态方法 */ CollectionsUtil.CreateCaseInsensitiveHashtable(); //建立或包装 Hashtable 等, 可初始化容量 CollectionsUtil.CreateCaseInsensitiveSortedList(); //建立有序的哈希表 SortedList
protected void Button1_Click(object sender, EventArgs e) { Hashtable hash = CollectionsUtil.CreateCaseInsensitiveHashtable(); //这就建立了一个忽略大小写的哈希表 hash["KEY1"] = 123; int n = (int)hash["key1"]; //123 TextBox1.Text = n.ToString(); try { hash.Add("Key1", 456); } catch (Exception err) { Response.Write(err.Message); } //已添加项。字典中的关键字:“KEY1”所添加的关键字:“Key1” }
protected void Button1_Click(object sender, EventArgs e) { SortedList sl = CollectionsUtil.CreateCaseInsensitiveSortedList(); //这就建立了一个忽略大小写的 SortedList sl["KEY1"] = 123; TextBox1.Text = sl["key1"].ToString(); //123 try { sl.Add("Key1", 456); } catch (Exception err) { Response.Write(err.Message); } //已添加项。字典中的关键字:“KEY1”所添加的关键字:“Key1” }
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"); //True bool b2 = hash.Contains("key1"); //False hash = CollectionsUtil.CreateCaseInsensitiveHashtable(hash); bool b3 = hash.Contains("key1"); //True TextBox1.Text = string.Concat(b1, "\n", b2, "\n", b3); }