Copy StringCollection to array, starting at the specified index of the target array in CSharp
Description
The following code shows how to copy StringCollection to array, starting at the specified index of the target array.
Example
using System;/*from w w w .j ava2 s .co m*/
using System.Collections;
using System.Collections.Specialized;
public class SamplesStringCollection {
public static void Main() {
StringCollection myCol = new StringCollection();
String[] myArr = new String[] { "A", "B", "C" };
myCol.AddRange( myArr );
String[] myArr2 = new String[myCol.Count];
myCol.CopyTo( myArr2, 0 );
for ( int i = 0; i < myArr2.Length; i++ ) {
Console.WriteLine(myArr2[i] );
}
}
}
The code above generates the following result.