একটি নোড লিঙ্কডলিস্ট কিনা তা পরীক্ষা করতে Contains() পদ্ধতি ব্যবহার করুন৷
এখানে আমাদের লিঙ্কডলিস্ট।
string [] students = {"Beth","Jennifer","Amy","Vera"};
LinkedList<string> list = new LinkedList<string>(students); এখন, "Amy" নোডটি তালিকায় আছে কি না তা পরীক্ষা করার জন্য, আমরা নীচে দেখানো হিসাবে Contains() পদ্ধতি ব্যবহার করব -
list.Contains("Amy") পদ্ধতিটি একটি বুলিয়ান মান প্রদান করবে যেমন এই ক্ষেত্রে সত্য।
আসুন আমরা সম্পূর্ণ কোড দেখি।
উদাহরণ
using System;
using System.Collections.Generic;
class Demo {
static void Main() {
string [] students = {"Beth","Jennifer","Amy","Vera"};
LinkedList<string> list = new LinkedList<string>(students);
foreach (var stu in list) {
Console.WriteLine(stu);
}
// adding a node at the end
var newNode = list.AddLast("Emma");
// adding a new node after the node added above
list.AddAfter(newNode, "Matt");
Console.WriteLine("LinkedList after adding new nodes...");
foreach (var stu in list) {
Console.WriteLine(stu);
}
Console.WriteLine("Is Student Amy (node) in the list?: "+list.Contains("Amy"));
Console.WriteLine("Is Student Anne (node) in the list?: "+list.Contains("Anne"));
}
} আউটপুট
Beth Jennifer Amy Vera LinkedList after adding new nodes... Beth Jennifer Amy Vera Emma Matt Is Student Amy (node) in the list?: True Is Student Anne (node) in the list?: False