কম্পিউটার টিউটোরিয়াল

C# Dictionary-এ কী-ভ্যালু জোড়া যোগ করা


C# Dictionary-এ কী-ভ্যালু জোড়া যোগ করতে, প্রথমে একটি Dictionary ঘোষণা করুন।

IDictionary<int, string> d = new Dictionary<int, string>();

এখন, KeyValuePair দিয়ে উপাদান যোগ করুন।

d.Add(new KeyValuePair<int, string>(1, "TVs")); d.Add(new KeyValuePair<int, string>(2, "Appliances")); d.Add(new KeyValuePair<int, string>(3, "Mobile"));

উপাদান যোগ করার পর, কী-ভ্যালু জোড়া প্রদর্শন করুন।

উদাহরণ

using System; using System.Collections.Generic; public class Demo {    public static void Main() {       IDictionary<int, string> d = new Dictionary<int, string>();       d.Add(new KeyValuePair<int, string>(1, "TVs"));       d.Add(new KeyValuePair<int, string>(2, "Appliances"));       d.Add(new KeyValuePair<int, string>(3, "Mobile"));       d.Add(new KeyValuePair<int, string>(4, "Tablet"));       d.Add(new KeyValuePair<int, string>(5, "Laptop"));       d.Add(new KeyValuePair<int, string>(6, "Desktop"));       d.Add(new KeyValuePair<int, string>(7, "Hard Drive"));       d.Add(new KeyValuePair<int, string>(8, "Flash Drive"));       foreach (KeyValuePair<int, string> ele in d) {          Console.WriteLine("Key = {0}, Value = {1}", ele.Key, ele.Value);       }    } }

আউটপুট

Key = 1, Value = TVs Key = 2, Value = Appliances Key = 3, Value = Mobile Key = 4, Value = Tablet Key = 5, Value = Laptop Key = 6, Value = Desktop Key = 7, Value = Hard Drive Key = 8, Value = Flash Drive

  1. উইন্ডোজ ১০-এ ডিকশনারিতে শব্দ যোগ বা মুছে ফেলার পদ্ধতি

  2. পাইথন ডিকশনারি থেকে কি-ভ্যালু অ্যাক্সেস করা

  3. পাইথনে ডিকশনারিতে কি-ভ্যালু পেয়ার যোগ করা

  4. পাইথনে ডিকশনারিতে নতুন কি যোগ করার পদ্ধতি