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

C#-এ SortedList-এ ডেটা খুঁজে বের করা ContainsKey এবং ContainsValue দিয়ে


C#-এ SortedList ক্লাসে কী (key) বা মান (value) আছে কিনা যাচাই করতে ContainsKey() এবং ContainsValue() মেথড ব্যবহার করা হয়। SortedList কী-ভ্যালু জোড়া সংরক্ষণ করে এবং কী অনুযায়ী সর্টেড রাখে।

উদাহরণ ১

using System;
using System.Collections;

public class Demo {
    public static void Main() {
        SortedList list = new SortedList();
        list.Add("1", "One");
        list.Add("2", "Two");
        list.Add("3", "Three");
        list.Add("4", "Four");
        list.Add("5", "Five");
        list.Add("6", "Six");
        list.Add("7", "Seven");
        list.Add("8", "Eight");
        
        Console.WriteLine("SortedList-এর কী এবং ভ্যালু....");
        foreach(DictionaryEntry k in list)
            Console.WriteLine("Key: {0}, Value: {1}", k.Key, k.Value);
        
        Console.WriteLine("SortedList-এ 'Three' ভ্যালু আছে কি? " + list.ContainsValue("Three"));
        Console.WriteLine("SortedList-এর আকার কি ফিক্সড? = " + list.IsFixedSize);
        Console.WriteLine("SortedList-এ কী '10' আছে কি? = " + list.ContainsKey("10"));
    }
}

আউটপুট

SortedList-এর কী এবং ভ্যালু....
Key: 1, Value: One
Key: 2, Value: Two
Key: 3, Value: Three
Key: 4, Value: Four
Key: 5, Value: Five
Key: 6, Value: Six
Key: 7, Value: Seven
Key: 8, Value: Eight
SortedList-এ 'Three' ভ্যালু আছে কি? True
SortedList-এর আকার কি ফিক্সড? = False
SortedList-এ কী '10' আছে কি? = False

উদাহরণ ২

আরেকটি উদাহরণ:

using System;
using System.Collections;

public class Demo {
    public static void Main(String[] args) {
        SortedList sortedList = new SortedList();
        sortedList.Add("A", "1");
        sortedList.Add("B", "2");
        sortedList.Add("C", "3");
        sortedList.Add("D", "4");
        sortedList.Add("E", "5");
        sortedList.Add("F", "6");
        sortedList.Add("G", "7");
        sortedList.Add("H", "8");
        sortedList.Add("I", "9");
        sortedList.Add("J", "10");
        
        Console.WriteLine("SortedList উপাদানগুলো...");
        foreach(DictionaryEntry d in sortedList) {
            Console.WriteLine("Key = " + d.Key + ", Value = " + d.Value);
        }
        
        Console.WriteLine("SortedList কী-ভ্যালু জোড়ার সংখ্যা = " + sortedList.Count);
        Console.WriteLine("\nSortedList-এ ইনামারেটর দিয়ে পুনরাবৃত্তি...");
        IDictionaryEnumerator demoEnum = sortedList.GetEnumerator();
        while (demoEnum.MoveNext())
            Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);
        
        Console.WriteLine("SortedList-এ কী 'M' আছে কি? = " + sortedList.ContainsKey("M"));
        Console.WriteLine("SortedList-এ কী 'H' আছে কি? = " + sortedList.ContainsKey("H"));
    }
}

আউটপুট

SortedList উপাদানগুলো...
Key = A, Value = 1
Key = B, Value = 2
Key = C, Value = 3
Key = D, Value = 4
Key = E, Value = 5
Key = F, Value = 6
Key = G, Value = 7
Key = H, Value = 8
Key = I, Value = 9
Key = J, Value = 10
SortedList কী-ভ্যালু জোড়ার সংখ্যা = 10
SortedList-এ ইনামারেটর দিয়ে পুনরাবৃত্তি...
Key = A, Value = 1
Key = B, Value = 2
Key = C, Value = 3
Key = D, Value = 4
Key = E, Value = 5
Key = F, Value = 6
Key = G, Value = 7
Key = H, Value = 8
Key = I, Value = 9
Key = J, Value = 10
SortedList-এ কী 'M' আছে কি? = False
SortedList-এ কী 'H' আছে কি? = True

  1. জাভাস্ক্রিপ্ট Set-এ অবজেক্ট কী সার্চ করা

  2. জাভাস্ক্রিপ্ট - ভেরিয়েবল দিয়ে অবজেক্ট কী সেট করা

  3. একটি কী ব্যতীত অবজেক্ট ডি-স্ট্রাকচারিং

  4. C#-এ SortedMap সমতুল্য: SortedList ক্লাস