主要成员:
/* 属性 */Count; ///* 方法 */Add(); //添加字符串AddRange(); //添加字符串数组Clear(); //清空Contains(); //是否存在CopyTo(); //复制到字符串数组IndexOf(); //取索引, 无则 -1Insert(); //插入Remove(); //删除指定元素RemoveAt(); //根据索引删除
简单测试:
protected void Button1_Click(object sender, EventArgs e){ StringCollection sc = new StringCollection(); sc.Add("AAA"); sc.Add("BBB"); sc.AddRange(new string[3] {"one", "two", "three"}); sc.Insert(1, "111"); sc.Insert(0, "000"); string str = ""; for (int i = 0; i < sc.Count; i++) { str += sc[i] + "; "; } TextBox1.Text = str; //000; AAA; 111; BBB; one; two; three; }protected void Button2_Click(object sender, EventArgs e){ StringCollection sc = new StringCollection(); string[] strArr = "aaa,bbb,ccc,ddd,eee,fff".Split(','); sc.AddRange(strArr); sc.RemoveAt(2); sc.Remove("ddd"); string str = ""; foreach (string s in sc) { str += s + "; "; } TextBox1.Text = str; //aaa; bbb; eee; fff; }