我有一个名为lst的List [0] "ABC" "DEF" "GHI"
[1] "JKL" "MNO" "PQR"
[2] etc, etc...
如何在每个第一个成员的末尾添加另一个字符串?
字符串s =“ EndOfBlock”;[0] "ABC" "DEF" "GHI" "EndOfBlock"
[1] "JKL" "MNO" "PQR" "EndOfBlock"
[2] etc, etc...
谢谢。
最佳答案
正如评论者所指出的,听起来您确实想要List<List<string>>
。但是,如果您想坚持使用List<string[]>
,这就是我扩展每个数组的方式。
List<string[]> list = ...
for(int i = 0; i < list.Count; i++)
{
// copy to a local variable (list[i] is a property, which can't be passed 'ref')
string[] array = list[i];
// resize the local variable. (this creates a new string[] object)
Array.Resize(ref array, array.Length + 1);
array[array.Length - 1] = "EndOfBlock";
// put the new object back in the list, replacing the old smaller one.
list[i] = array;
}
关于c# - C#-添加到字符串[]成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12587266/