Sorted List, Array और Hash Table का Combination है। इसमें Items की List होती है जिन्हें Key या Index का उपयोग करके Access किया जा सकता है।
SortedList में Specific Key से Associated Value को Gets और Sets करता है।
नए Elements Add करने के लिए भी Item Property का उपयोग कर सकते हैं।
यदि Key Exist नहीं करती, तो आप इसे ऐसे Include कर सकते हैं:
myCollection["myNonexistentKey"] = myValue
यदि Key पहले से Exist करती है, तो यह New Key और Value के साथ Overwrite कर देगा।
निम्न Example SortedList Class की Item Property के साथ काम करना सीखने के लिए है।
Example
using System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { SortedList s = new SortedList(); s.Add("S001", "Jack"); s.Add("S002", "Henry"); s["S003"] = "Brad"; // Keys का Collection Get करें। ICollection key = s.Keys; foreach (string k in key) { Console.WriteLine(k + ": " + s[k]); } } } }Output
S001: Jack S002: Henry S003: Brad