LinkedListNode<T> クラス

定義

LinkedList<T> のノードを表します。 このクラスは継承できません。

generic <typename T>
public ref class LinkedListNode sealed
public sealed class LinkedListNode<T>
[System.Runtime.InteropServices.ComVisible(false)]
public sealed class LinkedListNode<T>
type LinkedListNode<'T> = class
[<System.Runtime.InteropServices.ComVisible(false)>]
type LinkedListNode<'T> = class
Public NotInheritable Class LinkedListNode(Of T)

型パラメーター

T

リンク リストの要素の型を指定します。

継承
LinkedListNode<T>
属性

次のコード例では、 を LinkedListNode<T>作成し、 に LinkedList<T>追加し、そのプロパティの値を変更時に LinkedList<T> 追跡します。

#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.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

    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

End Class


'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>。 には LinkedListNode<T> 、値、それが属している への LinkedList<T> 参照、次のノードへの参照、および前のノードへの参照が含まれます。

コンストラクター

LinkedListNode<T>(T)

指定した値を含んだ LinkedListNode<T> クラスの新しいインスタンスを初期化します。

プロパティ

List

LinkedList<T> が属する LinkedListNode<T> を取得します。

Next

LinkedList<T> 内の次のノードを取得します。

Previous

LinkedList<T> 内の前のノードを取得します。

Value

ノードに格納された値を取得します。

ValueRef

ノードが保持する値への参照を取得します。

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象