将列表<t>添加到另一个列表的开头<t> </t> </t>

时间:2014-03-10 20:37:36

标签: c# string list insert

我正在寻找一种方法将List添加到另一个List的开头(特别是字符串)。

我找到了List.Insert方法,但这是针对单个对象的。

我已经考虑过为每个循环插入项目,但这会向后添加它们。

我该怎么做?

感谢。

2 个答案:

答案 0 :(得分:7)

您可以使用List.InsertRange

list.InsertRange(0, otherStrings);

答案 1 :(得分:0)

如果你想要一个新的清单,你需要做;

 List<Type> combinedLists = new List<Type>();
 combinedLists.AddRange(list1);
 combinedLists.AddRange(list2);

如果您希望它们按相反的顺序排列,请反转AddRange次来电。您还可以使用AddRange附加到任一列表的末尾,或使用InsertRange将列表添加到特定位置。

相关问题