StringDictionary.CopyTo(Array, int index) মেথড ব্যবহার করে স্ট্রিং ডিকশনারির কী/মান জোড়াগুলো একটি DictionaryEntry অ্যারেতে কপি করা যায়। StringDictionary কেস-ইনসেনসিটিভ কী সংরক্ষণ করে (কীগুলো স্বয়ংক্রিয়ভাবে লোয়ারকেসে রূপান্তরিত হয়)।
উদাহরণ ১: সূচক ০ থেকে পূর্ণ কপি
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringDictionary strDict = new StringDictionary();
strDict.Add("1", "SUV");
strDict.Add("2", "AUV");
strDict.Add("3", "Electric Car");
strDict.Add("4", "Utility Vehicle");
strDict.Add("5", "Hatchback");
strDict.Add("6", "Compact car");
strDict.Add("7", "MUV");
strDict.Add("8", "Crossover");
strDict.Add("9", "Covertible");
strDict.Add("10", "Quadricycle");
DictionaryEntry[] arr = {
new DictionaryEntry(), new DictionaryEntry(), new DictionaryEntry(),
new DictionaryEntry(), new DictionaryEntry(), new DictionaryEntry(),
new DictionaryEntry(), new DictionaryEntry(), new DictionaryEntry(),
new DictionaryEntry()
};
strDict.CopyTo(arr, 0);
for (int i = 0; i < arr.Length; i++) {
Console.WriteLine(arr[i].Key + " " + arr[i].Value);
}
}
}
আউটপুট
10 Quadricycle 1 SUV 2 AUV 3 Electric Car 4 Utility Vehicle 5 Hatchback 6 Compact car 7 MUV 8 Crossover 9 Covertible
উদাহরণ ২: সূচক ২ থেকে কপি (অ্যারে আকার ৮)
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringDictionary strDict = new StringDictionary();
strDict.Add("1", "SUV");
strDict.Add("2", "AUV");
strDict.Add("3", "Electric Car");
strDict.Add("4", "Utility Vehicle");
strDict.Add("5", "Hatchback");
strDict.Add("6", "Compact car");
DictionaryEntry[] arr = {
new DictionaryEntry(), new DictionaryEntry(), new DictionaryEntry(),
new DictionaryEntry(), new DictionaryEntry(), new DictionaryEntry(),
new DictionaryEntry(), new DictionaryEntry()
};
strDict.CopyTo(arr, 2); // সূচক ২ থেকে শুরু
for (int i = 0; i < arr.Length; i++) {
Console.WriteLine(arr[i].Key + " " + arr[i].Value);
}
}
}
আউটপুট
1 SUV 2 AUV 3 Electric Car 4 Utility Vehicle 5 Hatchback 6 Compact car
দ্রষ্টব্য: StringDictionary এনামারেশন ক্রম অনিশ্চিত (হ্যাশ-ভিত্তিক)। আউটপুটে কীগুলো লোয়ারকেসে দেখানো হয়েছে। আধুনিক C#-এ Dictionary<string, string> বা ConcurrentDictionary<string, string> ব্যবহার করা পছন্দনীয়।