यहां हमारी लिंक्डलिस्ट है।
int [] num = {1, 3, 7, 15};
LinkedList<int> list = new LinkedList<int>(num); यह जांचने के लिए कि सूची में कोई तत्व है या नहीं, इसमें शामिल हैं () विधि का उपयोग करें। निम्न उदाहरण सूची में नोड 3 के लिए जाँच करता है।
list.Contains(3)
ऊपर, रिटर्न सही है क्योंकि तत्व पाया जाता है जैसा कि नीचे दिखाया गया है -
उदाहरण
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