C# – How to copy items from list to list without foreach

ccopyforeachlistoop

How do I transfer the items contained in one List to another in C# without using foreach?

Best 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();

I see that this answer is still getting upvotes. Well, here's a secret for ya: the above answer is still using a foreach. Please don't upvote this any further.