다음은 LinkedList입니다.
int [] num = {1, 3, 7, 15};
LinkedList<int> list = new LinkedList<int>(num); 목록에 요소가 포함되어 있는지 확인하려면 Contains() 메서드를 사용합니다. 다음 예는 목록에서 노드 3을 확인합니다.
list.Contains(3)
위의 경우 요소가 아래와 같이 발견되었으므로 True를 반환합니다. -
예
using System;
using System.Collections.Generic;
class Demo {
static void Main() {
int [] num = {1, 3, 7, 15};
LinkedList<int> list = new LinkedList<int>(num);
foreach (var n in list) {
Console.WriteLine(n);
}
// adding a node at the end
var newNode = list.AddLast(20);
// adding a new node after the node added above
list.AddAfter(newNode, 30);
Console.WriteLine("LinkedList after adding new nodes...");
foreach (var n in list) {
Console.WriteLine(n);
}
Console.WriteLine("Is number 3 (node) in the list?: "+list.Contains(3));
}
} 출력
1 3 7 15 LinkedList after adding new nodes... 1 3 7 15 20 30 Is number 3 (node) in the list?: True