小编典典

将列表内容附加到另一个列表 C#

all

我有以下内容:

  1. 一个名为 GlobalStrings 的主列表
  2. 另一个名为 localStrings 的列表

例如在一个循环中:

List<string> GlobalStrings = new List<string>(); 
List<string> localStrings = new List<string>();
for(x=1;x<10;x++)
{
    localStrings.Add("some value"); 
    localStrings.Add("some value");
}
// Want to append localStrings to GlobalStrings as easily as possible

阅读 71

收藏
2022-07-13

共1个答案

小编典典

GlobalStrings.AddRange(localStrings);

注意:您不能使用接口 (IList) 声明列表对象。
文档:List<T>.AddRange(IEnumerable<T>).

2022-07-13