কম্পিউটার

C# এ HashSet এ উপাদান যোগ করুন


HashSet-এ উপাদান যোগ করতে, কোডটি নিম্নরূপ -

উদাহরণ

using System;
using System.Collections.Generic;
public class Demo {
   public static void Main(String[] args){
      HashSet<string> set1 = new HashSet<string>();
      set1.Add("A");
      set1.Add("B");
      set1.Add("C");
      set1.Add("D");
      set1.Add("E");
      set1.Add("F");
      set1.Add("G");
      set1.Add("H");
      Console.WriteLine("Elements in HashSet1...");
      foreach (string res in set1){
         Console.WriteLine(res);
      }
      HashSet<string> set2 = new HashSet<string>();
      set2.Add("John");
      set2.Add("Jacob");
      set2.Add("Ryan");
      set2.Add("Tom");
      set2.Add("Andy");
      set2.Add("Tim");
      set2.Add("Steve");
      set2.Add("Mark");
      Console.WriteLine("Elements in HashSet2... (Enumerator iterating through HashSet)");
      HashSet<string>.Enumerator demoEnum = set2.GetEnumerator();
      while (demoEnum.MoveNext()) {
         string res = demoEnum.Current;
         Console.WriteLine(res);
      }
      Console.WriteLine("Is HashSet1 equal to HashSet2? = "+set1.Equals(set2));
   }
}

আউটপুট

এটি নিম্নলিখিত আউটপুট −

তৈরি করবে
Elements in HashSet1...
A
B
C
D
E
F
G
H
Elements in HashSet2... (Enumerator iterating through HashSet)
John
Jacob
Ryan
Tom
Andy
Tim
Steve
Mark
Is HashSet1 equal to HashSet2? = False Count of HashSet2 = 8
Count of HashSet2 (updated) = 0

উদাহরণ

এখন আরেকটি উদাহরণ দেখা যাক -

using System;
using System.Collections.Generic;
public class Demo {
   public static void Main(String[] args){
      HashSet<int> set1 = new HashSet<int>();
      set1.Add(100);
      set1.Add(200);
      Console.WriteLine("Elements in HashSet1...");
      foreach (int res in set1){
         Console.WriteLine(res);
      }
      HashSet<int> set2 = new HashSet<int>();
      set2.Add(100);
      set2.Add(200);
      Console.WriteLine("Elements in HashSet2...");
      foreach (int res in set2){
         Console.WriteLine(res);
      }
      Console.WriteLine("Is set1 a subset of set2? "+set1.IsSubsetOf(set2));
   }
}

আউটপুট

এটি নিম্নলিখিত আউটপুট −

তৈরি করবে
Elements in HashSet1...
100
200
Elements in HashSet2...
100
200
Is set1 a subset of set2? True

  1. জাভাস্ক্রিপ্টের সাহায্যে কিভাবে একটি HTML এলিমেন্টে একটি আইডি যোগ করবেন

  2. কিভাবে একটি জাভাস্ক্রিপ্ট বস্তু একটি উপাদান যোগ করতে?

  3. Android ConcurrentLinkedDeque এ শেষ উপাদান কিভাবে যোগ করবেন?

  4. অ্যান্ড্রয়েড কনকারেন্টলিঙ্কডডিক-এ প্রথম উপাদান কীভাবে যুক্ত করবেন?