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

C# में ArrayList की शैलो कॉपी बनाना

उदाहरण 1: ArrayList को क्लोन करना

using System;
using System.Collections;

public class Demo {
    public static void Main() {
        ArrayList list = new ArrayList();
        list.Add("One");
        list.Add("Two");
        list.Add("Three");
        list.Add("Four");
        list.Add("Five");
        list.Add("Six");
        list.Add("Seven");
        list.Add("Eight");

        Console.WriteLine("ArrayList तत्व...");
        foreach(string str in list) {
            Console.WriteLine(str);
        }
        Console.WriteLine("ArrayList केवल पढ़ने योग्य? = " + list.IsReadOnly);
        Console.WriteLine("क्या तत्व Six ArrayList में है? = " + list.Contains("Six"));

        list.Insert(4, "Twelve");
        Console.WriteLine("\nArrayList तत्व... अपडेटेड");
        foreach(string str in list) {
            Console.WriteLine(str);
        }

        ArrayList list2 = new ArrayList();
        list2 = (ArrayList)list.Clone();
        Console.WriteLine("\nक्लोन किया गया ArrayList...");
        foreach(string str in list2) {
            Console.WriteLine(str);
        }
    }
}

आउटपुट

ArrayList तत्व...
One
Two
Three
Four
Five
Six
Seven
Eight
ArrayList केवल पढ़ने योग्य? = False
क्या तत्व Six ArrayList में है? = True
ArrayList तत्व... अपडेटेड
One
Two
Three
Four
Twelve
Five
Six
Seven
Eight
क्लोन किया गया ArrayList...
One
Two
Three
Four
Twelve
Five
Six
Seven
Eight

उदाहरण 2: डुप्लिकेट तत्वों के साथ ArrayList क्लोन करना

using System;
using System.Collections;

public class Demo {
    public static void Main(String[] args) {
        ArrayList list1 = new ArrayList();
        list1.Add("A");
        list1.Add("B");
        list1.Add("C");
        list1.Add("D");
        list1.Add("E");
        list1.Add("F");
        list1.Add("G");
        list1.Add("H");
        list1.Add("I");

        Console.WriteLine("ArrayList1 में तत्व...");
        foreach (string res in list1) {
            Console.WriteLine(res);
        }

        ArrayList list2 = new ArrayList();
        list2.Add("A");
        list2.Add("B");
        list2.Add("C");
        list2.Add("D");
        list2.Add("E");
        list2.Add("F");
        list2.Add("G");
        list2.Add("H");
        list2.Add("I");
        list2.Add("G");
        list2.Add("I");

        Console.WriteLine("ArrayList2 में तत्व...");
        foreach (string res in list2) {
            Console.WriteLine(res);
        }
        Console.WriteLine("ArrayList2 में तत्वों की संख्या = " + list2.Count);

        list2.Remove("G");
        Console.WriteLine("ArrayList2 में तत्व... (अपडेटेड)");
        foreach (string res in list2) {
            Console.WriteLine(res);
        }
        Console.WriteLine("ArrayList2 में तत्वों की संख्या (अपडेटेड) = " + list2.Count);

        ArrayList list3 = new ArrayList();
        list3 = (ArrayList)list2.Clone();
        Console.WriteLine("\nArrayList2 से क्लोन किया गया ArrayList...");
        foreach(string str in list3) {
            Console.WriteLine(str);
        }
    }
}

आउटपुट

ArrayList1 में तत्व...
A
B
C
D
E
F
G
H
I
ArrayList2 में तत्व...
A
B
C
D
E
F
G
H
I
G
I
ArrayList2 में तत्वों की संख्या = 11
ArrayList2 में तत्व... (अपडेटेड)
A
B
C
D
E
F
H
I
G
I
ArrayList2 में तत्वों की संख्या (अपडेटेड) = 10
ArrayList2 से क्लोन किया गया ArrayList...
A
B
C
D
E
F
H
I
G
I
  1. Outlook में ईमेल सिग्नेचर कैसे बनाएं और जोड़ें Outlook में ईमेल सिग्नेचर कैसे बनाएं और जोड़ें

    ईमेल में सबसे महत्वपूर्ण फीचर्स में से एक सिग्नेचर है जिसे ईमेल के अंत में जोड़ा जा सकता है और जिसमें संपर्क जानकारी, अभिवादन आदि शामिल होते हैं। ईमेल सिग्नेचर को ईमेल क्लाइंट में सेट किया जा सकता है, इसलिए हर बार एक नया ईमेल ड्राफ्ट करते समय उन्हें रीटाइप करने की आवश्यकता नहीं होती है। Microsoft Ou

  1. Outlook कैलेंडर में छुट्टियां कैसे बनाएं और जोड़ें Outlook कैलेंडर में छुट्टियां कैसे बनाएं और जोड़ें

    जानना चाहते हैं कि इस साल आपकी पसंदीदा छुट्टी कैलेंडर पर कब पड़ रही है? अपना Outlook कैलेंडर जांचें। Outlook का नवीनतम संस्करण आपके कैलेंडर में छुट्टियों और अन्य महत्वपूर्ण तिथियों को जोड़ना संभव बनाता है। Outlook के सभी संस्करण, पुराने या नए, कई देशों और धर्मों के लिए छुट्टियां शामिल करते हैं जिन्ह

  1. Excel में चेकलिस्ट कैसे बनाएं और जोड़ें Excel में चेकलिस्ट कैसे बनाएं और जोड़ें

    हम में से अधिकांश उन कार्यों को सूचीबद्ध करने के लिए टू-डू ऐप्स का उपयोग करते हैं जिन्हें हम किसी विशेष दिन करना चाहते हैं। यह हमें बिना किसी टालमटोल के अपने कार्यों को पूरा करने में मदद करता है। लेकिन, यदि आप मेरी तरह Excel प्रेमी हैं तो हम Microsoft Excel का उपयोग करके चेकलिस्ट या टू-डू सूची आसानी