কম্পিউটার

C# এ নির্দিষ্ট সূচকে অ্যারে উদাহরণে ListDictionary অনুলিপি করুন


নির্দিষ্ট সূচীতে লিস্টডিকশনারিকে অ্যারে ইনস্ট্যান্সে অনুলিপি করতে, কোডটি নিম্নরূপ -

উদাহরণ

using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
   public static void Main(){
      ListDictionary dict = new ListDictionary();
      dict.Add(1, "Harry");
      dict.Add(2, "Mark");
      dict.Add(3, "John");
      dict.Add(4, "Jacob");
      dict.Add(5, "Tim");
      dict.Add(6, "Sam");
      dict.Add(7, "Tom");
      dict.Add(8, "Kevin");
      Console.WriteLine("ListDictionary elements...");
      foreach(DictionaryEntry d in dict){
         Console.WriteLine(d.Key + " " + d.Value);
      }
      DictionaryEntry[] dictArr = new DictionaryEntry[dict.Count];
      Console.WriteLine("\nCopying to Array instance...");
      dict.CopyTo(dictArr, 0);
      for (int i = 0; i < dictArr.Length; i++) {
         Console.WriteLine("Key = "+dictArr[i].Key + ", Value = " + dictArr[i].Value);
      }
   }
}

আউটপুট

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

তৈরি করবে
ListDictionary elements...
1 Harry
2 Mark
3 John
4 Jacob
5 Tim
6 Sam
7 Tom
8 Kevin

Copying to Array instance...
Key = 1, Value = Harry
Key = 2, Value = Mark
Key = 3, Value = John
Key = 4, Value = Jacob
Key = 5, Value = Tim
Key = 6, Value = Sam
Key = 7, Value = Tom
Key = 8, Value = Kevin

উদাহরণ

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

using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
   public static void Main() {
      ListDictionary dict = new ListDictionary();
      dict.Add(1, "Harry");
      dict.Add(2, "Mark");
      dict.Add(3, "John");
      dict.Add(4, "Jacob");
      dict.Add(5, "Tim");
      Console.WriteLine("ListDictionary elements...");
      foreach(DictionaryEntry d in dict) {
         Console.WriteLine(d.Key + " " + d.Value);
      }
      DictionaryEntry[] dictArr = new DictionaryEntry[10];
      Console.WriteLine("\nCopying to Array instance...");
      dict.CopyTo(dictArr, 5);
      for (int i = 0; i < dictArr.Length; i++) {
         Console.WriteLine("Key = "+dictArr[i].Key + ", Value = " + dictArr[i].Value);
      }
   }
}

আউটপুট

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

তৈরি করবে
ListDictionary elements...
1 Harry
2 Mark
3 John
4 Jacob
5 Tim

Copying to Array instance...
Key = , Value =
Key = , Value =
Key = , Value =
Key = , Value =
Key = , Value =
Key = 1, Value = Harry
Key = 2, Value = Mark
Key = 3, Value = John
Key = 4, Value = Jacob
Key = 5, Value = Tim

  1. C# এ একটি সাজানো তালিকা বস্তুতে নির্দিষ্ট কীটির সূচী পাওয়া

  2. C# এ ListDictionary থেকে নির্দিষ্ট কী সহ এন্ট্রিটি সরান

  3. C# এ একটি সাজানো তালিকার নির্দিষ্ট সূচক থেকে সরান

  4. C# এ ListDictionary-এ নির্দিষ্ট কী-এর সাথে যুক্ত মান পান বা সেট করুন