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

C# में StringCollection में निर्दिष्ट इंडेक्स पर तत्व डालना

उदाहरण 1: StringCollection में एक तत्व डालना

using System;
using System.Collections.Specialized;

public class Demo {
    public static void Main() {
        StringCollection strCol = new StringCollection();
        strCol.Add("Accessories");
        strCol.Add("Books");
        strCol.Add("Electronics");

        Console.WriteLine("StringCollection तत्व...");
        foreach (string res in strCol) {
            Console.WriteLine(res);
        }

        strCol.Insert(2, "Headphone");
        Console.WriteLine("StringCollection तत्व... अपडेटेड");
        foreach (string res in strCol) {
            Console.WriteLine(res);
        }
    }
}

आउटपुट

StringCollection तत्व...
Accessories
Books
Electronics
StringCollection तत्व... अपडेटेड
Accessories
Books
Headphone
Electronics

उदाहरण 2: एकाधिक तत्व डालना

using System;
using System.Collections.Specialized;

public class Demo {
    public static void Main() {
        StringCollection strCol = new StringCollection();
        strCol.Add("Laptop");
        strCol.Add("Desktop");
        strCol.Add("Tablet");
        strCol.Add("Speakers");

        Console.WriteLine("StringCollection तत्व...");
        foreach (string res in strCol) {
            Console.WriteLine(res);
        }

        strCol.Insert(2, "Headphone");
        strCol.Insert(3, "Alienware");
        Console.WriteLine("StringCollection तत्व... अपडेटेड");
        foreach (string res in strCol) {
            Console.WriteLine(res);
        }

        strCol.Insert(4, "E-Book Reader");
        strCol.Insert(5, "Monitor");
        strCol.Insert(6, "HDD");
        strCol.Insert(7, "SSD");
        Console.WriteLine("StringCollection तत्व... अपडेटेड");
        foreach (string res in strCol) {
            Console.WriteLine(res);
        }
    }
}

आउटपुट

StringCollection तत्व...
Laptop
Desktop
Tablet
Speakers
StringCollection तत्व... अपडेटेड
Laptop
Desktop
Headphone
Alienware
Tablet
Speakers
StringCollection तत्व... अपडेटेड
Laptop
Desktop
Headphone
Alienware
E-Book Reader
Monitor
HDD
SSD
Tablet
Speakers
  1. - C# में ArrayList से निर्दिष्ट सूचकांक पर तत्व हटाएं

    C# में ArrayList वर्ग की RemoveAt(int index) विधि का उपयोग करके निर्दिष्ट सूचकांक पर स्थित तत्व को हटाया जा सकता है। यह विधि शून्य-आधारित सूचकांक स्वीकार करती है और तत्व हटाने के बाद शेष तत्वों को स्वचालित रूप से शिफ्ट कर देती है। उदाहरण 1: सूचकांक 5 पर तत्व हटाना using System; using System.Collect

  1. - C# में StringCollection से निर्दिष्ट सूचकांक पर तत्व हटाएं

    C# में StringCollection वर्ग की RemoveAt(int index) विधि का उपयोग करके निर्दिष्ट सूचकांक पर स्थित स्ट्रिंग को हटाया जा सकता है। यह विधि शून्य-आधारित सूचकांक स्वीकार करती है और तत्व हटाने के बाद शेष तत्वों को स्वचालित रूप से शिफ्ट कर देती है। उदाहरण 1: सूचकांक 3 पर तत्व हटाना using System; using Sys

  1. - C# में SortedList से निर्दिष्ट सूचकांक पर तत्व हटाएं

    C# में SortedList वर्ग की RemoveAt(int index) विधि का उपयोग करके निर्दिष्ट सूचकांक पर स्थित कुंजी-मान जोड़े को हटाया जा सकता है। चूंकि SortedList कुंजियों के आधार पर क्रमबद्ध होता है, सूचकांक क्रमबद्ध क्रम को दर्शाता है, सम्मिलन क्रम नहीं। उदाहरण 1: सूचकांक 3 पर तत्व हटाना using System; using Syste