Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> C#

C# में OrderedDictionary से सभी तत्व हटाएं

उदाहरण

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
  1. JavaScript का उपयोग करके क्यू से एलिमेंट्स हटाना JavaScript का उपयोग करके क्यू से एलिमेंट्स हटाना

    क्यू से एलिमेंट्स डीकीयू करने का अर्थ है उन्हें क्यू के फ्रंट/हेड से हटाना। हम कंटेनर एरे की शुरुआत को क्यू का हेड मान रहे हैं क्योंकि हम इसके संबंध में सभी ऑपरेशन्स करेंगे। इसलिए, हम पॉप फ़ंक्शन को इस प्रकार लागू कर सकते हैं: उदाहरण dequeue() {    // जांचें कि खाली है या नहीं   &nb

  1. - C# एरे से एलिमेंट डिलीट/रिमूव कैसे करें

    C# एरे से एलिमेंट हटाना C# में एरे फिक्स्ड साइज़ के होते हैं; एक बार बनने के बाद उनका आकार नहीं बदल सकता। डिलीट करने के लिए आपको: निर्दिष्ट इंडेक्स के बाद के एलिमेंट्स को एक स्थान बाएं शिफ्ट करना होगा। लॉजिकल साइज़ कम करना होगा (या नया छोटा एरे बनाना)। शिफ्टिंग एल्गोरिदम // pos = डिलीट करने की पो

  1. - जावा में ArrayList से सभी तत्वों को हटाना

    जावा में ArrayList से सभी तत्वों को हटाने के लिए, आइए पहले कुछ तत्वों के साथ एक ArrayList बनाएं: ArrayList<Integer> arrlist = new ArrayList<Integer>(5); arrlist.add(25); arrlist.add(50); arrlist.add(75); arrlist.add(100); arrlist.add(150); arrlist.add(200); arrlist.add(250); अब, आइए सभी