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

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

उदाहरण

SortedList की Clear() मेथड सूची से सभी की-वैल्यू जोड़े को हटा देती है। इस उदाहरण में एक SortedList बनाया गया है, उसमें 10 आइटम जोड़े गए हैं, फिर Clear() कॉल करके खाली किया गया है।

using System;
using System.Collections;

public class Demo {
    public static void Main(String[] args) {
        SortedList sortedList = new SortedList();
        sortedList.Add("A", "1");
        sortedList.Add("B", "2");
        sortedList.Add("C", "3");
        sortedList.Add("D", "4");
        sortedList.Add("E", "5");
        sortedList.Add("F", "6");
        sortedList.Add("G", "7");
        sortedList.Add("H", "8");
        sortedList.Add("I", "9");
        sortedList.Add("J", "10");

        Console.WriteLine("SortedList तत्व...");
        foreach(DictionaryEntry d in sortedList) {
            Console.WriteLine("Key = " + d.Key + ", Value = " + d.Value);
        }

        Console.WriteLine("SortedList की-वैल्यू जोड़े की संख्या = " + sortedList.Count);
        sortedList.Clear();
        Console.WriteLine("SortedList की संख्या (अपडेटेड) = " + sortedList.Count);
    }
}

आउटपुट

SortedList तत्व...
Key = A, Value = 1
Key = B, Value = 2
Key = C, Value = 3
Key = D, Value = 4
Key = E, Value = 5
Key = F, Value = 6
Key = G, Value = 7
Key = H, Value = 8
Key = I, Value = 9
Key = J, Value = 10
SortedList की-वैल्यू जोड़े की संख्या = 10
SortedList (अपडेटेड) = 0

एक और उदाहरण

using System;
using System.Collections;

public class Demo {
    public static void Main(String[] args) {
        SortedList sortedList = new SortedList();
        sortedList.Add("A", "1");
        sortedList.Add("B", "2");
        sortedList.Add("C", "3");

        Console.WriteLine("SortedList की-वैल्यू जोड़े की संख्या = " + sortedList.Count);
        Console.WriteLine("SortedList तत्व...");
        foreach(DictionaryEntry d in sortedList) {
            Console.WriteLine("Key = " + d.Key + ", Value = " + d.Value);
        }

        sortedList.Clear();
        Console.WriteLine("SortedList की-वैल्यू जोड़े की संख्या (अपडेटेड) = " + sortedList.Count);
    }
}

आउटपुट

SortedList की-वैल्यू जोड़े की संख्या = 3
SortedList तत्व...
Key = A, Value = 1
Key = B, Value = 2
Key = C, Value = 3
SortedList की-वैल्यू जोड़े की संख्या (अपडेटेड) = 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); अब, आइए सभी