StringDictionary 相當於 Key 和 Value 都是字串的雜湊表.
主要成員:
/* 屬性 */Count; //Keys; //鍵集合Values; //值集合/* 方法 */Add(); //Clear(); //ContainsKey(); //是否包含指定鍵ContainsValue(); //是否包含指定值CopyTo(); //將指定值賦值到數組Remove(); //根據鍵刪除
簡單練習:
protected void Button1_Click(object sender, EventArgs e){ StringDictionary sd = new StringDictionary(); sd.Add("k1", "AAA"); sd.Add("k2", "BBB"); sd.Add("k3", "CCC"); sd["k2"] = "bbb"; string str = ""; foreach (DictionaryEntry de in sd) //System.Collections.DictionaryEntry { str += string.Format("{0}:{1}; ", de.Key, de.Value); } TextBox1.Text = str; //k1:AAA; k2:bbb; k3:CCC; } protected void Button2_Click(object sender, EventArgs e){ StringDictionary sd = new StringDictionary(); sd.Add("k1", "AAA"); sd.Add("k2", "BBB"); sd.Add("k3", "CCC"); string str1, str2; str1 = str2 = ""; foreach (string s in sd.Keys) { str1 += s + ","; } //k1,k2,k3, foreach (string s in sd.Values) { str2 += s + ","; } //AAA,BBB,CCC, TextBox1.Text = str1 + "\n" + str2;}