C# List List(IEnumerable)

Description

List List (IEnumerable ) initializes a new instance of the List class that contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied.

Syntax


public List(
  IEnumerable<T> collection
)

Parameters

  • collection - The collection whose elements are copied to the new list.

Example

The following example demonstrates the List constructor.


/*from  ww w  .java2 s .co  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);

        Console.WriteLine("\nCapacity: {0}", myData.Capacity);

    }
}

The code above generates the following result.





















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




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack