学用 ASP.Net 之 System.Collections.Specialized.StringCollection 类


StringCollection 是专用于储存字符串的集合, 相当于字符串的动态数组.

主要成员:
/* 属性 */
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; 
}

转载于:https://my.oschina.net/hermer/blog/319634

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值