LinkedList.LinkedList() Constructor

Initializes a new instance of the LinkedList class that is empty.

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

Public Sub New
Dim instance As New LinkedList(Of T)
public LinkedList ()
public function LinkedList ()
Not applicable.

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

If the LinkedList is empty, the First and Last properties contain a null reference (Nothing in Visual Basic).

This constructor is an O(1) operation.

The following code example creates and initializes a LinkedList of type String, adds several nodes, and then displays its contents.

Imports System
Imports System.Collections
Imports System.Collections.Generic

Public Class GenericCollection

    Public Shared Sub Main()

        ' Create and initialize a new LinkedList.
        Dim ll As New LinkedList(Of String)()

        ' Display the contents of the LinkedList.
        If ll.Count > 0 Then
            Console.WriteLine("The first item in the list is {0}.", ll.First.Value)
            Console.WriteLine("The last item in the list is {0}.", ll.Last.Value)

            Console.WriteLine("The LinkedList contains:")
            For Each s As String In  ll
                Console.WriteLine("   {0}", s)
            Next s 
            Console.WriteLine("The LinkedList is empty.")
        End If

    End Sub 

End Class 

'This code produces the following output.
'The first item in the list is <null>.
'The last item in the list is orange.
'The LinkedList contains:
'   red
'   orange
'   yellow
'   orange

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