开发者社区 问答 正文

如何在C#中串联列表?

如果我有:

List myList1; List myList2;

myList1 = getMeAList(); // Checked myList1, it contains 4 strings

myList2 = getMeAnotherList(); // Checked myList2, it contains 6 strings

myList1.Concat(myList2); // Checked mylist1, it contains 4 strings... why? 我在Visual Studio 2008中运行了与此类似的代码,并在每次执行后设置了断点。在之后myList1 = getMeAList();,myList1包含四个字符串,然后我按下加号按钮以确保它们并非全部为空。

之后 myList2 = getMeAnotherList();,myList2包含六个字符串,然后检查

展开
收起
保持可爱mmm 2020-02-06 23:19:03 370 分享 版权
1 条回答
写回答
取消 提交回答
  • Concat返回一个新序列而不修改原始列表。尝试myList1.AddRange(myList2)。

    问题来源于stack overflow

    2020-02-06 23:19:20
    赞同 展开评论
问答分类:
C#
问答地址: