C# LinkedList CopyTo
Description
LinkedList
copies the entire LinkedList
Syntax
LinkedList.CopyTo
has the following syntax.
public void CopyTo(
T[] array,
int index
)
Parameters
array
- The one-dimensional Array that is the destination of the elements copied from LinkedList. The Array must have zero-based indexing. index
- The zero-based index in array at which copying begins.
Example
using System;/*from w ww .j a v a 2s . co m*/
using System.Collections;
using System.Collections.Generic;
class Sample
{
public static void Main()
{
//Create a List of Strings
//String-typed list
LinkedList<string> words = new LinkedList<string>();
words.AddFirst("A");
words.AddFirst("B");
words.AddFirst("C");
words.AddFirst("D");
words.AddFirst("E");
words.AddFirst("F");
string[] wordsArray = new string[10]; // Creates a new typed array
// Copy first two elements to the end of an existing array:
string[] existing = new string[1000];
words.CopyTo(existing,0);
}
}