/* 属性 */ 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; }