Re: [問題] 字串陣列中插入字串
※ 引述《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
討論串 (同標題文章)
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章