কম্পিউটার টিউটোরিয়াল

C#-এ ListDictionary-র নির্দিষ্ট আকার আছে কিনা যাচাই করুন

C#-এ ListDictionary ক্লাসের IsFixedSize প্রপার্টি ব্যবহার করে আপনি সহজেই যাচাই করতে পারেন যে ডিকশনারির আকার নির্দিষ্ট (fixed) কিনা। ListDictionary হল একটি সাধারণ ডিকশনারি বাস্তবায়ন যা ছোট ডেটা সেটের জন্য অপ্টিমাইজড। এর আকার ডাইনামিক্যালি পরিবর্তন করা যায়, তাই IsFixedSize সাধারণত false রিটার্ন করে।

উদাহরণ ১: ListDictionary-র বৈশিষ্ট্য যাচাই

using System;
using System.Collections;
using System.Collections.Specialized;

public class Demo {
    public static void Main() {
        ListDictionary dict1 = new ListDictionary();
        dict1.Add("A", "Books");
        dict1.Add("B", "Electronics");
        dict1.Add("C", "Smart Wearables");
        dict1.Add("D", "Pet Supplies");
        dict1.Add("E", "Clothing");
        dict1.Add("F", "Footwear");
        
        Console.WriteLine("ListDictionary1 উপাদানসমূহ...");
        foreach(DictionaryEntry d in dict1) {
            Console.WriteLine(d.Key + " " + d.Value);
        }
        Console.WriteLine("ListDictionary1-র নির্দিষ্ট আকার? = " + dict1.IsFixedSize);
        Console.WriteLine("ListDictionary1 রিড-অনলি? = " + dict1.IsReadOnly);
        Console.WriteLine("ListDictionary1 সিঙ্ক্রোনাইজড? = " + dict1.IsSynchronized);
        Console.WriteLine("ListDictionary1-তে 'M' কী আছে? = " + dict1.Contains("M"));
        
        ListDictionary dict2 = new ListDictionary();
        dict2.Add("1", "One");
        dict2.Add("2", "Two");
        dict2.Add("3", "Three");
        dict2.Add("4", "Four");
        dict2.Add("5", "Five");
        dict2.Add("6", "Six");
        
        Console.WriteLine("\nListDictionary2 কী-মান জোড়া...");
        IDictionaryEnumerator demoEnum = dict2.GetEnumerator();
        while (demoEnum.MoveNext())
            Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);
        Console.WriteLine("ListDictionary2-র নির্দিষ্ট আকার? = " + dict2.IsFixedSize);
        Console.WriteLine("ListDictionary2 রিড-অনলি? = " + dict2.IsReadOnly);
        Console.WriteLine("ListDictionary2 সিঙ্ক্রোনাইজড? = " + dict2.IsSynchronized);
        Console.WriteLine("ListDictionary2-তে '5' কী আছে? = " + dict2.Contains("5"));
    }
}

আউটপুট

ListDictionary1 উপাদানসমূহ...
A Books
B Electronics
C Smart Wearables
D Pet Supplies
E Clothing
F Footwear
ListDictionary1-র নির্দিষ্ট আকার? = False
ListDictionary1 রিড-অনলি? = False
ListDictionary1 সিঙ্ক্রোনাইজড? = False
ListDictionary1-তে 'M' কী আছে? = False

ListDictionary2 কী-মান জোড়া...
Key = 1, Value = One
Key = 2, Value = Two
Key = 3, Value = Three
Key = 4, Value = Four
Key = 5, Value = Five
Key = 6, Value = Six
ListDictionary2-র নির্দিষ্ট আকার? = False
ListDictionary2 রিড-অনলি? = False
ListDictionary2 সিঙ্ক্রোনাইজড? = False
ListDictionary2-তে '5' কী আছে? = True

উদাহরণ ২: আরও একটি উদাহরণ

using System;
using System.Collections;
using System.Collections.Specialized;

public class Demo {
    public static void Main() {
        ListDictionary dict = new ListDictionary();
        dict.Add("1", "SUV");
        dict.Add("2", "Sedan");
        dict.Add("3", "Utility Vehicle");
        dict.Add("4", "Compact Car");
        dict.Add("5", "SUV");
        dict.Add("6", "Sedan");
        dict.Add("7", "Utility Vehicle");
        dict.Add("8", "Compact Car");
        dict.Add("9", "Crossover");
        dict.Add("10", "Electric Car");
        
        Console.WriteLine("ListDictionary উপাদানসমূহ...");
        foreach(DictionaryEntry d in dict) {
            Console.WriteLine(d.Key + " " + d.Value);
        }
        Console.WriteLine("\nListDictionary-র নির্দিষ্ট আকার? = " + dict.IsFixedSize);
        Console.WriteLine("ListDictionary রিড-অনলি? = " + dict.IsReadOnly);
        Console.WriteLine("ListDictionary সিঙ্ক্রোনাইজড? = " + dict.IsSynchronized);
        Console.WriteLine("ListDictionary-তে 'K' কী আছে? = " + dict.Contains("K"));
        Console.WriteLine("ListDictionary-তে '9' কী আছে? = " + dict.Contains("9"));
    }
}

আউটপুট

ListDictionary উপাদানসমূহ...
1 SUV
2 Sedan
3 Utility Vehicle
4 Compact Car
5 SUV
6 Sedan
7 Utility Vehicle
8 Compact Car
9 Crossover
10 Electric Car
ListDictionary-র নির্দিষ্ট আকার? = False
ListDictionary রিড-অনলি? = False
ListDictionary সিঙ্ক্রোনাইজড? = False
ListDictionary-তে 'K' কী আছে? = False
ListDictionary-তে '9' কী আছে? = True

নোট: ListDictionary কখনোই নির্দিষ্ট আকারের হয় না; এটি সবসময় ডাইনামিক। IsFixedSize প্রপার্টি সবসময় false রিটার্ন করে।

  1. C#-এ Collection-এ উপাদান রয়েছে কিনা তা যাচাই করুন

  2. C#-এ অ্যারে ফিক্সড সাইজ কিনা তা যাচাই করুন

  3. C#-এ লিস্ট খালি কিনা চেক করা

  4. পাইথনে যাচাই করুন বাইনারি স্ট্রিং-এ m সংখ্যক সবুজ ১ বা ০ আছে কিনা