কম্পিউটার

স্ট্রিংডিকশনারিতে C# এ একটি নির্দিষ্ট কী রয়েছে কিনা তা পরীক্ষা করুন


স্ট্রিংডিকশনারিতে একটি নির্দিষ্ট কী আছে কিনা তা পরীক্ষা করতে, কোডটি নিম্নরূপ −

উদাহরণ

using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
   public static void Main(){
      StringDictionary strDict1 = new StringDictionary();
      strDict1.Add("A", "John");
      strDict1.Add("B", "Andy");
      strDict1.Add("C", "Tim");
      strDict1.Add("D", "Ryan");
      strDict1.Add("E", "Kevin");
      strDict1.Add("F", "Katie");
      strDict1.Add("G", "Brad");
      Console.WriteLine("StringDictionary1 elements...");
      foreach(DictionaryEntry d in strDict1){
         Console.WriteLine(d.Key + " " + d.Value);
      }
      Console.WriteLine("Does StringDictionary1 has key G? "+strDict1.ContainsKey("G"));
      StringDictionary strDict2 = new StringDictionary();
      strDict2.Add("A", "John");
      strDict2.Add("B", "Andy");
      strDict2.Add("C", "Tim");
      strDict2.Add("D", "Ryan");
      strDict2.Add("E", "Kevin");
      strDict2.Add("F", "Katie");
      strDict2.Add("G", "Brad");
      Console.WriteLine("\nStringDictionary2 elements...");
      foreach(DictionaryEntry d in strDict2){
         Console.WriteLine(d.Key + " " + d.Value);
      }
      Console.WriteLine("\nIs Dictionary2 equal to Dictionary1? = "+strDict2.Equals(strDict1));
   }
}

আউটপুট

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

তৈরি করবে
StringDictionary1 elements...
a John
b Andy
c Tim
d Ryan
e Kevin
f Katie
g Brad
Does StringDictionary1 has key G? True StringDictionary2 elements...
a John
b Andy
c Tim
d Ryan
e Kevin
f Katie
g Brad
Is Dictionary2 equal to Dictionary1? = False

উদাহরণ

আসুন আরেকটি উদাহরণ দেখি -

using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
   public static void Main(){
      StringDictionary strDict1 = new StringDictionary();
      strDict1.Add("A", "John");
      strDict1.Add("B", "Andy");
      strDict1.Add("C", "Tim");
      strDict1.Add("D", "Ryan");
      strDict1.Add("E", "Kevin");
      strDict1.Add("F", "Katie");
      strDict1.Add("G", "Brad");
      Console.WriteLine("StringDictionary1 elements...");
      foreach(DictionaryEntry d in strDict1){
         Console.WriteLine(d.Key + " " + d.Value);
      }
      Console.WriteLine("Does StringDictionary1 has key G? "+strDict1.ContainsKey("G"));
      StringDictionary strDict2 = new StringDictionary();
      strDict2.Add("A", "John");
      strDict2.Add("B", "Andy");
      strDict2.Add("C", "Tim");
      strDict2.Add("D", "Ryan");
      strDict2.Add("E", "Kevin");
      strDict2.Add("F", "Katie");
      strDict2.Add("G", "Brad");
      Console.WriteLine("\nStringDictionary2 elements...");
      foreach(DictionaryEntry d in strDict2){
         Console.WriteLine(d.Key + " " + d.Value);
      }
      Console.WriteLine("\nIs Dictionary2 equal to Dictionary1? = "+strDict2.Equals(strDict1));
      Console.WriteLine("Does StringDictionary2 has key B? "+strDict2.ContainsKey("B"));
   }
}

আউটপুট

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

তৈরি করবে
StringDictionary1 elements...
a John
b Andy
c Tim
d Ryan
e Kevin
f Katie
g Brad
Does StringDictionary1 has key G? True StringDictionary2 elements...
a John
b Andy
c Tim
d Ryan
e Kevin
f Katie
g Brad
Is Dictionary2 equal to Dictionary1? = False
Does StringDictionary2 has key B? True

  1. বাছাই করা সেটটিতে C# এ একটি নির্দিষ্ট উপাদান রয়েছে কিনা তা পরীক্ষা করুন

  2. হ্যাশটেবলে C# এ একটি নির্দিষ্ট মান রয়েছে কিনা তা পরীক্ষা করুন

  3. একটি উপাদান C# এর সংগ্রহে আছে কিনা তা পরীক্ষা করুন

  4. একটি হ্যাশসেটে C# এ নির্দিষ্ট উপাদান রয়েছে কিনা তা পরীক্ষা করুন