SortedList একটি সাজানো কী-মান জোড়ার কালেকশন। এর IsReadOnly প্রপার্টি চেক করে জানা যায় যে কালেকশনটি পড়া-মাত্র (read-only) কিনা। সাধারণ SortedList রিড-অনলি নয় (false রিটার্ন করে)।
উদাহরণ ১: SortedList-এ মান এবং কী প্রিন্ট
using System;
using System.Collections;
public class Demo {
public static void Main(String[] args) {
SortedList list = new SortedList();
list.Add("One", "IT");
list.Add("Two ", "Operations");
list.Add("Three", "Marketing");
list.Add("Four", "Purchase");
list.Add("Five", "Sales");
list.Add("Six", "Finance");
Console.WriteLine("SortedList উপাদানসমূহ...");
foreach(DictionaryEntry d in list) {
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("\nমানের তালিকা... SortedList");
IList col = list.GetValueList();
foreach(string res in col) {
Console.WriteLine(res);
}
Console.WriteLine("\nSortedList রিড-অনলি? = " + list.IsReadOnly);
}
}
আউটপুট
SortedList উপাদানসমূহ...
Five Sales
Four Purchase
One IT
Six Finance
Three Marketing
Two Operations
মানের তালিকা... SortedList
Sales
Purchase
IT
Finance
Marketing
Operations
SortedList রিড-অনলি? = False
উদাহরণ ২: কী কালেকশন এবং ইনডেক্স খোঁজা
using System;
using System.Collections;
public class Demo {
public static void Main(String[] args) {
SortedList list = new SortedList();
list.Add("One", "Finance");
list.Add("Two", "Marketing");
list.Add("Three", "Sales");
list.Add("Four", "Purchase");
list.Add("Five", "Operations");
list.Add("Six", "IT");
Console.WriteLine("SortedList উপাদানসমূহ...");
foreach(DictionaryEntry d in list) {
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("\nকী 'One'-র ইনডেক্স = " + list.IndexOfKey("One"));
ICollection col = list.Keys;
Console.WriteLine("\nকীগুলোর কালেকশন...");
foreach(string res in col)
Console.WriteLine(res);
Console.WriteLine("\nSortedList রিড-অনলি? = " + list.IsReadOnly);
}
}
আউটপুট
SortedList উপাদানসমূহ...
Five Operations
Four Purchase
One Finance
Six IT
Three Sales
Two Marketing
কী 'One'-র ইনডেক্স = 2
কীগুলোর কালেকশন...
Five
Four
One
Six
Three
Two
SortedList রিড-অনলি? = False
নোট: SortedList অর্ডার মেইনটেইন করে কী অনুযায়ী। IsReadOnly সবসময় false রিটার্ন করে যদি না র্যাপার ব্যবহার করা হয়।