उदाहरण
OrderedDictionary की Clear() मेथड डिक्शनरी से सभी की-वैल्यू जोड़े को हटा देती है। इस उदाहरण में एक OrderedDictionary बनाया गया है, उसमें आइटम जोड़े गए हैं, फिर Clear() कॉल करके खाली किया गया है।
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
OrderedDictionary dict = new OrderedDictionary();
dict.Add("A", "Books");
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 Books B Electronics C Smart Wearables D Pet Supplies E Clothing F Footwear OrderedDictionary में तत्वों की संख्या = 6 OrderedDictionary में तत्वों की संख्या (अपडेटेड) = 0
एक और उदाहरण
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
OrderedDictionary dict = new OrderedDictionary();
dict.Add("1", "AB");
dict.Add("2", "CD");
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 तत्व... 1 AB 2 CD OrderedDictionary में तत्वों की संख्या = 2 OrderedDictionary में तत्वों की संख्या (अपडेटेड) = 0