C# List ToArray

Description

List ToArray copies the elements of the List to a new array.

Syntax

List.ToArray has the following syntax.


public T[] ToArray()

Example

The following example demonstrates the ToArray method.


/*from   w  w w .  jav  a 2  s .  c  o  m*/
using System;
using System.Collections.Generic;

public class Example
{
    public static void Main()
    {
        string[] input = { "A", "B", "C" };

        List<string> myData = new List<string>(input);
        string[] output = myData.GetRange(2, 3).ToArray();

        Console.WriteLine();
        foreach( string myD in output )
        {
            Console.WriteLine(myD);
        }
    }
}




















Home »
  C# Tutorial »
    System.Collections.Generic »




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack