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

C# में जांचें कि ArrayList का आकार निश्चित है या नहीं

ArrayList.IsFixedSize गुण इंगित करता है कि ArrayList का आकार निश्चित है या नहीं। मानक ArrayList इंस्टेंस false लौटाते हैं (आकार बदल सकते हैं)। निश्चित आकार रैपर के लिए ArrayList.FixedSize(ArrayList) का उपयोग करें।

उदाहरण 1: सिंक्रनाइज़्ड रैपर (निश्चित आकार नहीं)

using System;
using System.Collections;

public class Demo
{
    public static void Main(String[] args)
    {
        ArrayList list1 = new ArrayList();
        list1.Add("One");
        list1.Add("Two");
        list1.Add("Three");
        list1.Add("Four");
        list1.Add("Five");
        Console.WriteLine("Elements in ArrayList...");
        foreach (string res in list1)
        {
            Console.WriteLine(res);
        }
        ArrayList list = ArrayList.Synchronized(list1);
        Console.WriteLine("Is ArrayList synchronized? = " + list.IsSynchronized);
        Console.WriteLine("Is ArrayList have a fixed size? = " + list.IsFixedSize);
    }
}

आउटपुट

Elements in ArrayList...
One
Two
Three
Four
Five
Is ArrayList synchronized? = True
Is ArrayList have a fixed size? = False

उदाहरण 2: फिक्स्ड साइज रैपर

using System;
using System.Collections;

public class Demo
{
    public static void Main(String[] args)
    {
        ArrayList list1 = new ArrayList();
        list1.Add("ABC");
        list1.Add("BCD");
        list1.Add("CDE");
        list1.Add("DEF");
        list1.Add("EFG");
        list1.Add("GHI");
        list1.Add("HIJ");
        list1.Add("IJK");
        list1.Add("JKL");
        list1.Add("KLM");
        Console.WriteLine("Elements in ArrayList...");
        foreach (string res in list1)
        {
            Console.WriteLine(res);
        }
        ArrayList list = ArrayList.Synchronized(list1);
        Console.WriteLine("Is ArrayList synchronized? = " + list.IsSynchronized);
        ArrayList list2 = ArrayList.FixedSize(list1);
        Console.WriteLine("Is ArrayList have a fixed size? = " + list2.IsFixedSize);
    }
}

आउटपुट

Elements in ArrayList...
ABC
BCD
CDE
DEF
EFG
GHI
HIJ
IJK
JKL
KLM
Is ArrayList synchronized? = True
Is ArrayList have a fixed size? = True

ArrayList.FixedSize एक रैपर बनाता है जो Add, Remove, Clear, Insert आदि को ब्लॉक करता है (NotSupportedException फेंकता है)। मौजूदा तत्वों को संशोधित करने की अनुमति देता है (इंडेक्सर सेट)। IsFixedSize रैपर पर true लौटाता है। यह क्षमता को प्रभावित नहीं करता।

  1. - Python Pandas - जांचें कि इंडेक्स में NaN हैं या नहीं

    परिचय पैंडास इंडेक्स में NaN (नॉट अ नंबर) मानों की उपस्थिति की जांच के लिए index.hasnans प्रॉपर्टी का उपयोग करें। आवश्यक लाइब्रेरी आयात करें import pandas as pd import numpy as np NaN मानों वाला इंडेक्स बनाएं NaN के लिए नम्पाई लाइब्रेरी का उपयोग किया गया है। index = pd.Index([Car, Bike, np.nan, Ca

  1. - Python Pandas - जांचें कि इंडेक्स में डुप्लिकेट मान हैं या नहीं

    परिचय पैंडास इंडेक्स में डुप्लिकेट मानों की उपस्थिति की जांच के लिए index.has_duplicates प्रॉपर्टी का उपयोग करें। आवश्यक लाइब्रेरी आयात करें import pandas as pd इंडेक्स बनाएं index = pd.Index([Car, Bike, Truck, Car, Airplane]) इंडेक्स प्रदर्शित करें print(पैंडास इंडेक्स...\n, index) डुप्लिकेट मा

  1. - Python Pandas - जांचें कि इंडेक्स में अद्वितीय मान हैं या नहीं

    परिचय पैंडास इंडेक्स के सभी मानों के अद्वितीय (यूनिक) होने की जांच के लिए index.is_unique प्रॉपर्टी का उपयोग करें। आवश्यक लाइब्रेरी आयात करें import pandas as pd इंडेक्स बनाएं index = pd.Index([50, 40, 30, 20, 10]) इंडेक्स प्रदर्शित करें print(पैंडास इंडेक्स...\n, index) अद्वितीय मानों की जांच क