দুটি লিঙ্কডলিস্ট অবজেক্ট সমান কিনা তা পরীক্ষা করতে, কোডটি নিম্নরূপ -
উদাহরণ
using System; using System.Collections.Generic; public class Demo { public static void Main(String[] args){ LinkedList<string> list1 = new LinkedList<string>(); list1.AddLast("One"); list1.AddLast("Two"); list1.AddLast("Three"); list1.AddLast("Four"); list1.AddLast("Five"); Console.WriteLine("Elements in LinkedList1..."); foreach (string res in list1){ Console.WriteLine(res); } LinkedList<string> list2 = new LinkedList<string>(); list2.AddLast("India"); list2.AddLast("US"); list2.AddLast("UK"); list2.AddLast("Canada"); list2.AddLast("Poland"); list2.AddLast("Netherlands"); Console.WriteLine("Elements in LinkedList2..."); foreach (string res in list2){ Console.WriteLine(res); } LinkedList<string> list3 = new LinkedList<string>(); list3 = list2; Console.WriteLine("Is LinkedList3 equal to LinkedList2? = "+list3.Equals(list2)); } }
আউটপুট
এটি নিম্নলিখিত আউটপুট তৈরি করবে −
Elements in LinkedList1... One Two Three Four Five Elements in LinkedList2... India US UK Canada Poland Netherlands Is LinkedList3 equal to LinkedList2? = True
উদাহরণ
আসুন আরেকটি উদাহরণ দেখি -
using System; using System.Collections.Generic; public class Demo { public static void Main(String[] args){ LinkedList<string> list1 = new LinkedList<string>(); list1.AddLast("One"); list1.AddLast("Two"); list1.AddLast("Three"); list1.AddLast("Four"); list1.AddLast("Five"); Console.WriteLine("Elements in LinkedList1..."); foreach (string res in list1){ Console.WriteLine(res); } LinkedList<string> list2 = new LinkedList<string>(); list2.AddLast("India"); list2.AddLast("US"); list2.AddLast("UK"); list2.AddLast("Canada"); list2.AddLast("Poland"); list2.AddLast("Netherlands"); Console.WriteLine("Elements in LinkedList2..."); foreach (string res in list2){ Console.WriteLine(res); } Console.WriteLine("Is LinkedList2 equal to LinkedList1? = "+list2.Equals(list1)); } }
আউটপুট
এটি নিম্নলিখিত আউটপুট তৈরি করবে −
Elements in LinkedList1... One Two Three Four Five Elements in LinkedList2... India US UK Canada Poland Netherlands Is LinkedList2 equal to LinkedList1? = False