In this example, I will show you how to copy a list items without using references.
Been looking around for awhile for a solution to this problem and it doesn’t sound like something which is simple. Now I found the solution.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var listA = new List<int>(); listA.Add(100); listA.Add(200); listA.Add(300); listA.Add(400); listA.Add(500); listA.Add(600); listA.Add(700); var listB = new List<int>(listA.Count); listA.ForEach((item) => { listB.Add((item)); }); Console.ReadLine(); } } |