LinkedListNode<T> Class

Определение

Представляет узел в LinkedList<T>. Represents a node in a LinkedList<T>. Этот класс не наследуется. This class cannot be inherited.

[System.Runtime.InteropServices.ComVisible(false)]
public sealed class LinkedListNode<T>
Параметры типа
T

Указывает тип элементов связанного списка. Specifies the element type of the linked list.

Наследование
LinkedListNode<T>
Атрибуты

Примеры

В следующем примере кода создается LinkedListNode<T>, добавляет его в LinkedList<T>и отслеживает значения его свойств, как LinkedList<T> изменения.The following code example creates a LinkedListNode<T>, adds it to a LinkedList<T>, and tracks the values of its properties as the LinkedList<T> changes.

#using <System.dll>

using namespace System;
using namespace System::Collections::Generic;

public ref class GenericCollection  {

public:
   static void Main()  {

      // Create a new LinkedListNode of type String and displays its properties.
      LinkedListNode<String^>^ lln = gcnew LinkedListNode<String^>( "orange" );
      Console::WriteLine( "After creating the node ...." );
      DisplayProperties( lln );

      // Create a new LinkedList.
      LinkedList<String^>^ ll = gcnew LinkedList<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 );

   }

   static void DisplayProperties( LinkedListNode<String^>^ lln )  {
      if ( lln->List == nullptr )
         Console::WriteLine( "   Node is not linked." );
      else
         Console::WriteLine( "   Node belongs to a linked list with {0} elements.", lln->List->Count );

      if ( lln->Previous == nullptr )
         Console::WriteLine( "   Previous node is null." );
      else
         Console::WriteLine( "   Value of previous node: {0}", lln->Previous->Value );

      Console::WriteLine( "   Value of current node:  {0}", lln->Value );

      if ( lln->Next == nullptr )
         Console::WriteLine( "   Next node is null." );
      else
         Console::WriteLine( "   Value of next node:     {0}", lln->Next->Value );

      Console::WriteLine();
   }

};

int main()
{
    GenericCollection::Main();
}

/*

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

*/
using System;
using System.Collections.Generic;

public class GenericCollection  {

   public static void Main()  {

      // Create a new LinkedListNode of type String and displays its properties.
      LinkedListNode<String> lln = new LinkedListNode<String>( "orange" );
      Console.WriteLine( "After creating the node ...." );
      DisplayProperties( lln );

      // Create a new LinkedList.
      LinkedList<String> ll = new LinkedList<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 );

   }

   public static void DisplayProperties( LinkedListNode<String> lln )  {
      if ( lln.List == null )
         Console.WriteLine( "   Node is not linked." );
      else
         Console.WriteLine( "   Node belongs to a linked list with {0} elements.", lln.List.Count );

      if ( lln.Previous == null )
         Console.WriteLine( "   Previous node is null." );
      else
         Console.WriteLine( "   Value of previous node: {0}", lln.Previous.Value );

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

      if ( lln.Next == null )
         Console.WriteLine( "   Next node is null." );
      else
         Console.WriteLine( "   Value of next node:     {0}", lln.Next.Value );

      Console.WriteLine();
   }

}


/*

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

*/
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

Комментарии

Каждый элемент LinkedList<T> коллекция LinkedListNode<T>.Each element of the LinkedList<T> collection is a LinkedListNode<T>. LinkedListNode<T> Содержит ссылку на значение LinkedList<T> , к которому он принадлежит, ссылку на следующий узел, а также ссылка на предыдущий узел.The LinkedListNode<T> contains a value, a reference to the LinkedList<T> that it belongs to, a reference to the next node, and a reference to the previous node.

Конструкторы

LinkedListNode<T>(T)

Инициализирует новый экземпляр класса LinkedListNode<T> содержащего указанное значение. Initializes a new instance of the LinkedListNode<T> class, containing the specified value.

Свойства

List

Получает коллекцию LinkedList<T>, которой принадлежит узел LinkedListNode<T>. Gets the LinkedList<T> that the LinkedListNode<T> belongs to.

Next

Получает следующий узел в коллекции LinkedList<T>. Gets the next node in the LinkedList<T>.

Previous

Получает предыдущий узел в коллекции LinkedList<T>. Gets the previous node in the LinkedList<T>.

Value

Возвращает значение, содержащееся в узле. Gets the value contained in the node.

Методы

Equals(Object)

Определяет, равен ли заданный объект текущему объекту. Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Служит хэш-функцией по умолчанию. Serves as the default hash function.

(Inherited from Object)
GetType()

Возвращает объект Type для текущего экземпляра. Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Создает неполную копию текущего объекта Object. Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Возвращает строку, представляющую текущий объект. Returns a string that represents the current object.

(Inherited from Object)

Применяется к