How do I copy items from list to list without foreach?

后端 未结 8 1643
野的像风
野的像风 2020-11-30 17:42

How do I transfer the items contained in one List to another in C# without using foreach?

8条回答
  •  粉色の甜心
    2020-11-30 18:04

    To add the contents of one list to another list which already exists, you can use:

    targetList.AddRange(sourceList);
    

    If you're just wanting to create a new copy of the list, see Lasse's answer.

提交回复
热议问题