作者psvsps2 (Op颖)
看板C_Sharp
标题Re: [问题] 字串阵列中插入字串
时间Fri Jun 10 23:49:06 2005
※ 引述《gla (预)》之铭言:
: 找不到解法
: 我想在字串阵列中插入字串
: 比如
: string[] str={boy,girl,cool.dog}
: 变成
: str={boy,girl,pig,cool.dog}
: 有方法吗
: 不知道用add能不能做到
: 不过我弄不出来
: 求高手赐教了..
1.System.Array 有实作 ICollection 这个介面
2.ArrayList的Constructor(建构子)可以接收ICollection
3.ArrayList可以任意插入Element
4.ArrayList有一个ToArray()的Method...
ICollection collection = (ICollection)str;
ArrayList list = new ArrayList(collection);
//加你要加的Element
object[] newstr = ArrayList.ToArray();
Console.WriteLine((sting)newstr[2]);
上面是不好的例子建议继承CollectionBase实作一个Strong name 的collection calss
比较正统
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.229.23.6