.NET List Concat vs AddRange

后端 未结 3 901
死守一世寂寞
死守一世寂寞 2020-11-27 16:46

What is the difference between the AddRange and Concat functions on a generic List? Is one recommended over the other?

3条回答
  •  醉酒成梦
    2020-11-27 17:11

    They have totally different semantics.

    AddRange modifies the list by adding the other items to it.

    Concat returns a new sequence containing the list and the other items, without modifying the list.

    Choose whichever one has the semantics you want.

提交回复
热议问题