उदाहरण 1: OrderedDictionary में तत्व जोड़ना और गिनना
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
OrderedDictionary dict = new OrderedDictionary();
dict.Add("A", "Home Appliances");
dict.Add("B", "Electronics");
dict.Add("C", "Smart Wearables");
dict.Add("D", "Pet Supplies");
dict.Add("E", "Clothing");
dict.Add("F", "Footwear");
Console.WriteLine("OrderedDictionary तत्व...");
foreach(DictionaryEntry d in dict) {
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("OrderedDictionary में तत्वों की संख्या = " + dict.Count);
dict.Clear();
Console.WriteLine("OrderedDictionary में तत्वों की संख्या (अपडेटेड) = " + dict.Count);
}
}
आउटपुट
OrderedDictionary तत्व...
A Home Appliances
B Electronics
C Smart Wearables
D Pet Supplies
E Clothing
F Footwear
OrderedDictionary में तत्वों की संख्या = 6
OrderedDictionary में तत्वों की संख्या (अपडेटेड) = 0
उदाहरण 2: दो OrderedDictionary की तुलना और ReadOnly जांच
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
OrderedDictionary dict1 = new OrderedDictionary();
dict1.Add("A", "John");
dict1.Add("B", "Andy");
dict1.Add("C", "Jacob");
dict1.Add("D", "Kevin");
dict1.Add("E", "Gary");
dict1.Add("F", "Nathan");
dict1.Add("G", "Kevin");
dict1.Add("H", "Ryan");
Console.WriteLine("OrderedDictionary1 तत्व...");
foreach(DictionaryEntry d in dict1) {
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("OrderedDictionary1 में कुंजी-मान जोड़ों की संख्या = " + dict1.Count);
OrderedDictionary dict2 = new OrderedDictionary();
dict2.Add("1", "One");
dict2.Add("2", "Two");
dict2.Add("3", "Three");
dict2.Add("4", "Four");
dict2.Add("5", "Five");
dict2.Add("6", "Six");
Console.WriteLine("\nOrderedDictionary2 तत्व...");
foreach(DictionaryEntry d in dict2) {
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("OrderedDictionary2 में कुंजी-मान जोड़ों की संख्या = " + dict2.Count);
Console.WriteLine("\nक्या OrderedDictionary1, OrderedDictionary2 के बराबर है? = " + (dict1.Equals(dict2)));
OrderedDictionary orderedDict = dict2.AsReadOnly();
Console.WriteLine("क्या OrderedDictionary केवल पढ़ने योग्य है? = " + orderedDict.IsReadOnly);
}
}
आउटपुट
OrderedDictionary1 तत्व...
A John
B Andy
C Jacob
D Kevin
E Gary
F Nathan
G Kevin
H Ryan
OrderedDictionary1 में कुंजी-मान जोड़ों की संख्या = 8
OrderedDictionary2 तत्व...
1 One
2 Two
3 Three
4 Four
5 Five
6 Six
OrderedDictionary2 में कुंजी-मान जोड़ों की संख्या = 6
क्या OrderedDictionary1, OrderedDictionary2 के बराबर है? = False
क्या OrderedDictionary केवल पढ़ने योग्य है? = True