13,004,774 members (66,495 online)
Rate this:
See more:
Hello everyone,
if i have List1, List2, List3, List4, List5, List6,

How can i copy all the values inside each list in a new List( ListTotal)

Posted 31-Jan-13 10:10am
z3ngew855

Rate this:

## Solution 3

You can use AddRange[^] property if you don't want to use linq:

```var l1 = new List<string> {"a", "b"};
var l2 = new List<string> {"c", "d"};

var res = new List<string>();
Rate this:

## Solution 1

the Union() extension method.

newList = list1.Union(list2).Union(list3);

I should point out that Union() filters out duplicates. If you want duplicates or know there are nonde, use Concat().
v2
Rate this:

## Solution 2

You can try this C# 2.0 solution (no LINQ is required here).
```using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// Create sample lists
var list1 = new List<string> { "A", "B", "C" };
var list2 = new List<string> { "D", "E" };
var list3 = new List<string> { "F", "G", "H" };

// "Concatenate" lists into one enumeration
var e4 = ConcatLists(list1, list2, list3);

// Create one list from enumerable sequence
var l4 = new List<string>(e4);

// Print items
foreach (var item in l4)
Console.WriteLine(item);

// Wait
}

public static IEnumerable<T> ConcatLists<T>(params List<T>[] lists)
{
foreach (var list in lists)
{
foreach (var item in list)
{
yield return item;
}
}
}
}
}```

Top Experts
Last 24hrsThis month
 Richard MacCutchan 145 RickZeeland 145 OriginalGriff 125 F-ES Sitecore 125 Dave Kreskowiak 105
 OriginalGriff 5,030 ppolymorphe 2,617 RickZeeland 2,495 Kornfeld Eliyahu Peter 2,126 Richard Deeming 1,693