C#-এ OrderedDictionary.Values প্রপার্টি একটি ICollection রিটার্ন করে যাতে OrderedDictionary-এ থাকা সব মান (values) থাকে। OrderedDictionary কি-ভ্যালু পেয়ারের ক্রম বজায় রাখে (insertion order)।
উদাহরণ ১: মানগুলো কপি করে অ্যারে-এ প্রদর্শন
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main(){
OrderedDictionary dict = new OrderedDictionary();
dict.Add("1", "One");
dict.Add("2", "Two");
dict.Add("3", "Three");
dict.Add("4", "Four");
dict.Add("5", "Five");
dict.Add("6", "Six");
dict.Add("7", "Seven");
dict.Add("8", "Eight");
ICollection col = dict.Values;
String[] strVal = new String[dict.Count];
col.CopyTo(strVal, 0);
Console.WriteLine("Displaying the values...");
for (int i = 0; i < dict.Count; i++) {
Console.WriteLine(strVal[i]);
}
}
}
আউটপুট
Displaying the values... One Two Three Four Five Six Seven Eight
উদাহরণ ২: ভিন্ন কি-ভ্যালু পেয়ারের সাথে মানগুলো প্রদর্শন
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main(){
OrderedDictionary dict = new OrderedDictionary();
dict.Add("One", "John");
dict.Add("Two", "Tim");
dict.Add("Three", "Katie");
dict.Add("Four", "Andy");
dict.Add("Five", "Gary");
dict.Add("Six", "Amy");
ICollection col = dict.Values;
String[] strVal = new String[dict.Count];
col.CopyTo(strVal, 0);
Console.WriteLine("Displaying the Values...");
for (int i = 0; i < dict.Count; i++) {
Console.WriteLine(strVal[i]);
}
}
}
আউটপুট
Displaying the Values... John Tim Katie Andy Gary Amy
OrderedDictionary-এর অন্যান্য গুরুত্বপূর্ণ সদস্য
| সদস্য | বিবরণ |
|---|---|
Keys | সব কি (key)-এর ICollection রিটার্ন করে |
Values | সব মান (value)-এর ICollection রিটার্ন করে |
[key] | নির্দিষ্ট কির মান পাওয়া/সেট করা (ইন্ডেক্সার) |
Add(key, value) | নতুন কি-ভ্যালু পেয়ার যোগ করে |
Remove(key) | নির্দিষ্ট কির এন্ট্রি সরিয়ে দেয় |
Clear() | সব এন্ট্রি সরিয়ে দেয় |
মূল পয়েন্টস
Valuesপ্রপার্টি একটি স্ন্যাপশট (snapshot) রিটার্ন করে - ডিকশনারি পরিবর্তন করলে কালেকশন আপডেট হয় না।CopyTo()মেথড ব্যবহার করে অ্যারে-এ কপি করা যায়।- OrderedDictionary
System.Collections.Specializedনেমস্পেসে থাকে। - জেনেরিক বিকল্প হিসেবে
Dictionary<TKey, TValue>(অনর্ডার্ড) বা কাস্টম ইমপ্লিমেন্টেশন ব্যবহার করা যায়।