Adds items of another list (or an IEnumerable collection) to the end of the list.
Using AddRange method:
1 2 3 | listA.AddRange(listB); |
AddRange example:
Firstly, set a list in C# and add elements. after add listB to listA
1 2 3 4 5 6 7 8 9 10 11 12 | var listA = new List<int>(); listA.Add(100); listA.Add(200); listA.Add(300); listA.Add(400); var listB = new List<int>(); listB.Add(500); listB.Add(600); listA.AddRange(listB); //ListA -> 100,200,300,400,500,600 |
Full 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 | using System; using System.Collections.Generic; class Program { static void Main(string[] args) { var listA = new List<int>(); listA.Add(100); listA.Add(200); listA.Add(300); listA.Add(400); var listB = new List<int>(); listB.Add(500); listB.Add(600); listA.AddRange(listB); //ListA -> 100,200,300,400,500,600 Console.ReadLine(); } } |