ratty ratty - 3 months ago 16
C# Question

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

How do I transfer the items contained in one

List
to another in C# without using
foreach
?

Answer

You could try this:

List<Int32> copy = new List<Int32>(original);

or if you're using C# 3 and .NET 3.5, with Linq, you can do this:

List<Int32> copy = original.ToList();
Comments