/* 属性 */ Count; //元素数 Keys; //键集合 Values; //值集合 /* 方法 */ Add(); //添加 Clear(); //清空 Contains(); //是否包含 CopyTo(); //将指定元素复制到数组 Insert(); //插入 Remove(); //根据键删除 RemoveAt(); //根据索引删除
protected void Button1_Click(object sender, EventArgs e) { OrderedDictionary od = new OrderedDictionary(); od.Add("k1", 111); od.Add("k2", 222); od.Add("k3", 333); string s1 = od["k2"].ToString(); //222 string s2 = od[1].ToString(); //222 string s3 = "", s4 = ""; for (int i = 0; i < od.Count; i++) { s3 += od[i].ToString() + "; "; //111; 222; 333; } foreach (DictionaryEntry de in od) { s4 += string.Format("{0}:{1}; ", de.Key, de.Value); } TextBox1.Text = s1 + "\n" + s2 + "\n" + s3 + "\n" + s4; //k1:111; k2:222; k3:333; }