/* 属性 */ Count; // /* 方法 */ Add(); //添加字符串 AddRange(); //添加字符串数组 Clear(); //清空 Contains(); //是否存在 CopyTo(); //复制到字符串数组 IndexOf(); //取索引, 无则 -1 Insert(); //插入 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; }