C# List AddRange
Description
List
adds the elements of the specified
collection to the end of the List
Syntax
public void AddRange(
IEnumerable<T> collection
)
Parameters
collection
- The collection whose elements should be added to the end of the List. The collection itself cannot be null, but it can contain elements that are null, if type T is a reference type.
Example
The following code shows how to add elements a List.
using System;/*w w w . j a v a 2s .c o m*/
using System.Collections;
using System.Collections.Generic;
class Sample
{
public static void Main()
{
List<string> words = new List<string>();
words.AddRange(new[] { "C", "D" });
foreach (string s in words) {
Console.WriteLine ("all:"+s); // all words
}
}
}
The code above generates the following result.