This documentation is archived and is not being maintained.

LinkedList.LinkedList(Generic IEnumerable) Constructor

Initializes a new instance of the LinkedList class that contains elements copied from the specified IEnumerable and has sufficient capacity to accommodate the number of elements copied.

Namespace: System.Collections.Generic
Assembly: System (in system.dll)

public LinkedList (
	IEnumerable<T> collection
public LinkedList (
	IEnumerable<T> collection
public function LinkedList (
	collection : IEnumerable<T>
Not applicable.



The IEnumerable whose elements are copied to the new LinkedList.

Exception typeCondition


collection is a null reference (Nothing in Visual Basic).

LinkedList accepts a null reference (Nothing in Visual Basic) as a valid Value for reference types and allows duplicate values.

If collection has no elements then the new LinkedList is empty, and the First and Last properties contain a null reference (Nothing in Visual Basic).

This constructor is an O(n) operation, where n is the number of elements in collection.

The following code example and output demonstrate the LinkedList(Generic IEnumerable) constructor. The example creates an array of strings, then creates and populates a LinkedList by passing the array of strings to the constructor.

This code and output are part of a larger example provided for the LinkedList class.

// Create the link list.
string[] words =
    { "the", "fox", "jumped", "over", "the", "dog" };
LinkedList<string> sentence = new LinkedList<string>(words);

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0