LinkedListNode(Of T) Class

Represents a node in a LinkedList(Of T). This class cannot be inherited.

System.Object
  System.Collections.Generic.LinkedListNode(Of T)

Namespace:  System.Collections.Generic
Assemblies:   System (in System.dll)
  System.Collections (in System.Collections.dll)

'Declaration
<ComVisibleAttribute(False)> _
Public NotInheritable Class LinkedListNode(Of T)

Type Parameters

T

Specifies the element type of the linked list.

The LinkedListNode(Of T) type exposes the following members.

  NameDescription
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryLinkedListNode(Of T)Initializes a new instance of the LinkedListNode(Of T) class, containing the specified value.
Top

  NameDescription
Public propertySupported by the XNA FrameworkSupported by Portable Class LibraryListGets the LinkedList(Of T) that the LinkedListNode(Of T) belongs to.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibraryNextGets the next node in the LinkedList(Of T).
Public propertySupported by the XNA FrameworkSupported by Portable Class LibraryPreviousGets the previous node in the LinkedList(Of T).
Public propertySupported by the XNA FrameworkSupported by Portable Class LibraryValueGets the value contained in the node.
Top

  NameDescription
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryToStringReturns a string that represents the current object. (Inherited from Object.)
Top

Each element of the LinkedList(Of T) collection is a LinkedListNode(Of T). The LinkedListNode(Of T) contains a value, a reference to the LinkedList(Of T) that it belongs to, a reference to the next node, and a reference to the previous node.

The following code example creates a LinkedListNode(Of T), adds it to a LinkedList(Of T), and tracks the values of its properties as the LinkedList(Of T) changes.

Imports System
Imports System.Collections.Generic

Public Class GenericCollection

    Public Shared Sub Main()

        ' Create a new LinkedListNode of type String and displays its properties. 
        Dim lln As New LinkedListNode(Of String)("orange")
        Console.WriteLine("After creating the node ....")
        DisplayProperties(lln)

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

        ' Add the "orange" node and display its properties.
        ll.AddLast(lln)
        Console.WriteLine("After adding the node to the empty LinkedList ....")
        DisplayProperties(lln)

        ' Add nodes before and after the "orange" node and display the "orange" node's properties.
        ll.AddFirst("red")
        ll.AddLast("yellow")
        Console.WriteLine("After adding red and yellow ....")
        DisplayProperties(lln)

    End Sub 'Main

    Public Shared Sub DisplayProperties(lln As LinkedListNode(Of String))

        If lln.List Is Nothing Then
            Console.WriteLine("   Node is not linked.")
        Else
            Console.WriteLine("   Node belongs to a linked list with {0} elements.", lln.List.Count)
        End If  

        If lln.Previous Is Nothing Then
            Console.WriteLine("   Previous node is null.")
        Else
            Console.WriteLine("   Value of previous node: {0}", lln.Previous.Value)
        End If 

        Console.WriteLine("   Value of current node:  {0}", lln.Value)

        If lln.Next Is Nothing Then
            Console.WriteLine("   Next node is null.")
        Else
            Console.WriteLine("   Value of next node:     {0}", lln.Next.Value)
        End If 

        Console.WriteLine()

    End Sub 'DisplayProperties 

End Class 'GenericCollection


'This code produces the following output. 

'After creating the node .... 
'   Node is not linked. 
'   Previous node is null. 
'   Value of current node:  orange 
'   Next node is null. 

'After adding the node to the empty LinkedList .... 
'   Node belongs to a linked list with 1 elements. 
'   Previous node is null. 
'   Value of current node:  orange 
'   Next node is null. 

'After adding red and yellow .... 
'   Node belongs to a linked list with 3 elements. 
'   Value of previous node: red 
'   Value of current node:  orange 
'   Value of next node:     yellow

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft