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

C#-এ ListDictionary ক্লাস

ListDictionary ক্লাস IDictionary ইমপ্লিমেন্ট করে একটি সিঙ্গলি লিঙ্কড লিস্ট ব্যবহার করে। এটি ছোট কালেকশন (সাধারণত ১০টি নিচে) জন্য উপযুক্ত।

ListDictionary-এর প্রপার্টিগুলো

ক্রমপ্রপার্টি ও বর্ণনা
1Count — কী/ভ্যালু জোড়ার সংখ্যা।
2IsFixedSize — ফিক্সড সাইজ কিনা।
3IsReadOnly — রিড-অনলি কিনা।
4IsSynchronized — থ্রেড-সেফ কিনা।
5Item[Object] — নির্দিষ্ট কীর মান পাওয়া/সেট করা।
6Keys — সব কীগুলোর কালেকশন।
7SyncRoot — সিঙ্ক্রোনাইজেশনের জন্য অবজেক্ট।
8Values — সব ভ্যালুগুলোর কালেকশন।

ListDictionary-এর মেথডসমূহ

ক্রমমেথড ও বর্ণনা
1Add(Object, Object) — কী/ভ্যালু জোড়া যোগ করে।
2Clear() — সব এন্ট্রি মুছে ফেলে।
3Contains(Object) — নির্দিষ্ট কী আছে কিনা চেক করে।
4CopyTo(Array, Int32) — এন্ট্রিগুলো অ্যারেতে কপি করে।
5GetEnumerator() — IDictionaryEnumerator রিটার্ন করে।

উদাহরণ ১: প্রপার্টি চেক করা

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 elements...");
        foreach(DictionaryEntry d in dict1) {
            Console.WriteLine(d.Key + " " + d.Value);
        }

        Console.WriteLine("Is the ListDictionary1 having fixed size? = " + dict1.IsFixedSize);
        Console.WriteLine("If ListDictionary1 read-only? = " + dict1.IsReadOnly);
        Console.WriteLine("Is ListDictionary1 synchronized = " + dict1.IsSynchronized);
        Console.WriteLine("The ListDictionary1 has the key M? = " + dict1.Contains("M"));
    }
}

আউটপুট

ListDictionary1 elements...
A Books
B Electronics
C Smart Wearables
D Pet Supplies
E Clothing
F Footwear
Is the ListDictionary1 having fixed size? = False
If ListDictionary1 read-only? = False
Is ListDictionary1 synchronized = False
The ListDictionary1 has the key M? = 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");
        // ... বাকি এন্ট্রি যোগ করুন

        ListDictionary dict2 = new ListDictionary();
        dict2.Add("1", "One");
        dict2.Add("2", "Two");
        // ... বাকি এন্ট্রি যোগ করুন

        ListDictionary dict3 = new ListDictionary();
        dict3 = dict2; // একই রেফারেন্স

        Console.WriteLine("Is ListDictionary3 equal to ListDictionary2? = " + (dict3.Equals(dict2)));
    }
}

আউটপুট

Is ListDictionary3 equal to ListDictionary2? = True

নোট

Equals মেথড রেফারেন্স সমতা চেক করে, কন্টেন্ট সমতা নয়। কন্টেন্ট مقایনা করতে নিজে লিখতে হবে।

  1. C# Console ক্লাস

  2. জাভা সিরিয়ালাইজেশনে অবজেক্ট গ্রাফ (Object Graph)

  3. পাইথন টাইপ অবজেক্ট (Type Object) - সব কিছু অবজেক্ট, ক্লাসও অবজেক্ট

  4. পাইথনে অবজেক্ট-অরিয়েন্টেড প্রোগ্রামিং (Object Oriented Programming in Python)