Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET List<T> Concat vs AddRange

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

like image 221
johnc Avatar asked Sep 19 '08 07:09

johnc


1 Answers

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.

like image 115
Greg Beech Avatar answered Oct 09 '22 08:10

Greg Beech