HybridDictionary.CopyTo() मेथड डिक्शनरी एंट्रीज़ को DictionaryEntry ऐरे में कॉपी करता है। आप लक्ष्य ऐरे में प्रारंभिक इंडेक्स निर्दिष्ट कर सकते हैं।
उदाहरण 1: इंडेक्स 2 से कॉपी करना (बड़े ऐरे में)
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
HybridDictionary dict = new HybridDictionary();
dict.Add("1", "SUV");
dict.Add("2", "AUV");
dict.Add("3", "Utility Vehicle");
dict.Add("4", "MUV");
dict.Add("5", "Compact Car");
dict.Add("6", "Convertible");
Console.WriteLine("HybridDictionary की और वैल्यू पेयर्स...");
foreach (DictionaryEntry entry in dict) {
Console.WriteLine("{0} and {1}", entry.Key, entry.Value);
}
// 10 आकार का ऐरे, इंडेक्स 2 से कॉपी करें
DictionaryEntry[] dictArr = new DictionaryEntry[10];
Console.WriteLine("\nऐरे इंस्टेंस में कॉपी किया गया (इंडेक्स 2 से)...");
dict.CopyTo(dictArr, 2);
for (int i = 0; i < dictArr.Length; i++) {
Console.WriteLine("Key = " + dictArr[i].Key + ", Value = " + dictArr[i].Value);
}
}
}
आउटपुट
HybridDictionary की और वैल्यू पेयर्स...
1 and SUV
2 and AUV
3 and Utility Vehicle
4 and MUV
5 and Compact Car
6 and Convertible
ऐरे इंस्टेंस में कॉपी किया गया (इंडेक्स 2 से)...
Key = , Value =
Key = , Value =
Key = 1, Value = SUV
Key = 2, Value = AUV
Key = 3, Value = Utility Vehicle
Key = 4, Value = MUV
Key = 5, Value = Compact Car
Key = 6, Value = Convertible
Key = , Value =
Key = , Value =
उदाहरण 2: इंडेक्स 0 से कॉपी करना (सटीक आकार के ऐरे में)
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
HybridDictionary dict = new HybridDictionary(10); // प्रारंभिक क्षमता
dict.Add("1", "SUV");
dict.Add("2", "AUV");
dict.Add("3", "Utility Vehicle");
dict.Add("4", "MUV");
Console.WriteLine("HybridDictionary की और वैल्यू पेयर्स...");
foreach (DictionaryEntry entry in dict) {
Console.WriteLine("{0} and {1}", entry.Key, entry.Value);
}
// 10 आकार का ऐरे, इंडेक्स 0 से कॉपी करें
DictionaryEntry[] dictArr = new DictionaryEntry[10];
Console.WriteLine("\nऐरे इंस्टेंस में कॉपी किया गया (इंडेक्स 0 से)...");
dict.CopyTo(dictArr, 0);
for (int i = 0; i < dictArr.Length; i++) {
Console.WriteLine("Key = " + dictArr[i].Key + ", Value = " + dictArr[i].Value);
}
}
}
आउटपुट
HybridDictionary की और वैल्यू पेयर्स...
1 and SUV
2 and AUV
3 and Utility Vehicle
4 and MUV
ऐरे इंस्टेंस में कॉपी किया गया (इंडेक्स 0 से)...
Key = 1, Value = SUV
Key = 2, Value = AUV
Key = 3, Value = Utility Vehicle
Key = 4, Value = MUV
Key = , Value =
Key = , Value =
Key = , Value =
Key = , Value =
Key = , Value =
Key = , Value =
मुख्य बिंदु
CopyTo(DictionaryEntry[], int)मेथड का उपयोग करें।- लक्ष्य ऐरे
DictionaryEntry[]प्रकार का होना चाहिए। - इंडेक्स पैरामीटर लक्ष्य ऐरे में प्रारंभिक स्थिति है।
- खाली स्लॉट्स में डिफ़ॉल्ट DictionaryEntry (null की/वैल्यू) होते हैं।
- कॉपी क्रम आंतरिक स्टोरेज क्रम का अनुसरण करता है (जरूरी नहीं कि सॉर्टेड हो)।