LinkedListNode<T>.Previous 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
LinkedList<T>의 이전 노드를 가져옵니다.
public:
property System::Collections::Generic::LinkedListNode<T> ^ Previous { System::Collections::Generic::LinkedListNode<T> ^ get(); };
public System.Collections.Generic.LinkedListNode<T> Previous { get; }
public System.Collections.Generic.LinkedListNode<T>? Previous { get; }
member this.Previous : System.Collections.Generic.LinkedListNode<'T>
Public ReadOnly Property Previous As LinkedListNode(Of T)
속성 값
LinkedList<T>의 이전 노드에 대한 참조이거나, 현재 노드가 First의 첫 번째 요소(LinkedList<T>)이면 null
입니다.
예제
다음 코드 예제에서는 을 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
적용 대상
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET