Copy a sub List to an array starting at the specified index of the target array in CSharp
Description
The following code shows how to copy a sub List to an array starting at the specified index of the target array.
Example
using System;/*from w ww. j a v a2 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[100];
words.CopyTo(0, existing, 8, 2);
foreach(String s in existing){
Console.WriteLine(s);
}
}
}
The code above generates the following result.