Copy List to and array, starting at the beginning of the target array in CSharp
Description
The following code shows how to copy List to and array, starting at the beginning of the target array.
Example
using System;//ww w . j a va 2 s . c om
using System.Collections;
using System.Collections.Generic;
class Sample
{
public static void Main()
{
List<string> words = new List<string>();
words.Add("A");
words.Add("B");
words.Add("C");
words.Add("D");
words.Add("E");
words.Add("F");
string[] existing = new string[10];
words.CopyTo(existing);
foreach(String s in existing){
Console.WriteLine(s);
}
}
}
The code above generates the following result.