কম্পিউটার

C# এ স্ট্রিংডিকশনারিতে মানের একটি সংগ্রহ পান


স্ট্রিংডিকশনারিতে মানের একটি সংগ্রহ পেতে, কোডটি নিম্নরূপ −

উদাহরণ

using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
   public static void Main(){
      StringDictionary strDict1 = new StringDictionary();
      strDict1.Add("S", "Home Appliances");
      strDict1.Add("T", "Smart Wearable Tech");
      strDict1.Add("U", "Electronics");
      strDict1.Add("V", "Toys");
      strDict1.Add("W", "Books");
      strDict1.Add("X", "Accessories");
      Console.WriteLine("StringDictionary elements...");
      foreach(DictionaryEntry d in strDict1){
         Console.WriteLine(d.Key + " " + d.Value);
      }
      Console.WriteLine("\nCollection of keys and values...");
      String[] keyArr = new String[strDict1.Count];
      strDict1.Keys.CopyTo(keyArr, 0);
      for (int i = 0; i < strDict1.Count; i++) {
         Console.WriteLine("Key "+(i+1)+" = "+keyArr[i]+", Value "+(i+1)+" = "+strDict1[keyArr[i]]);
      }
      Console.WriteLine("\nDoes StringDictionary has key B? "+strDict1.ContainsKey("B"));
   }
}

আউটপুট

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

তৈরি করবে
StringDictionary elements...
x Accessories
s Home Appliances
t Smart Wearable Tech
u Electronics
v Toys
w Books
Collection of keys and values...
Key 1 = x, Value 1 = Accessories
Key 2 = s, Value 2 = Home Appliances
Key 3 = t, Value 3 = Smart Wearable Tech
Key 4 = u, Value 4 = Electronics
Key 5 = v, Value 5 = Toys
Key 6 = w, Value 6 = Books
Does StringDictionary has key B? 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("StringDictionary elements...");
      foreach(DictionaryEntry d in strDict1){
         Console.WriteLine(d.Key + " " + d.Value);
      }
      Console.WriteLine("\nCollection of keys and values...");
      String[] keyArr = new String[strDict1.Count];
      strDict1.Keys.CopyTo(keyArr, 0);
      for (int i = 0; i < strDict1.Count; i++) {
         Console.WriteLine("Key "+(i+1)+" = "+keyArr[i]+", Value "+(i+1)+" = "+strDict1[keyArr[i]]);
      }
      Console.WriteLine("\nDoes StringDictionary has key B? "+strDict1.ContainsKey("B"));
   }
}

আউটপুট

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

তৈরি করবে
tringDictionary elements...
a John
b Andy
c Tim
d Ryan
e Kevin
f Katie
g Brad
Collection of keys and values...
Key 1 = a, Value 1 = John
Key 2 = b, Value 2 = Andy
Key 3 = c, Value 3 = Tim
Key 4 = d, Value 4 = Ryan
Key 5 = e, Value 5 = Kevin
Key 6 = f, Value 6 = Katie
Key 7 = g, Value 7 = Brad
Does StringDictionary has key B? True

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

  2. জাভাস্ক্রিপ্টে একটি বস্তুর মান কিভাবে পেতে হয়?

  3. একটি MongoDB সংগ্রহে সব নাম পান

  4. একটি MongoDB সংগ্রহে সমস্ত কীগুলির নাম পান৷