1

I am using using concat right now to merge lists together but that only allows me to merge two lists together but when I try to merge a third list together it doesnt allow me to do that with my code below.

    new List <items> theListOne = new List <items> ();
    new List <items> theListTwo = new List <items> ();
    new List <items> theListThree = new List <items> ();

    var result = theListOne.Concat(theListTwo).ToList();

If I want more than two lists together, how would i solve that?

Paul
  • 1,175
  • 8
  • 15
medvedo
  • 543
  • 2
  • 8
  • 23

1 Answers1

3

You can concat as many enumerables as you want

var result = theListOne.Concat(theListTwo).Concat(theListThree)....ToList();

Make sure to use ToList() only once at the end to avoid useless enumerations

Ondra
  • 1,619
  • 13
  • 27
  • Thanks. Works ;) Will give you the answer in 5 mins (cannot accept an answer to soon after i posted it) – medvedo May 13 '16 at 17:17