SortedList में निर्दिष्ट कुंजी से संबद्ध मान प्राप्त करने या सेट करने के लिए, कोड इस प्रकार है -
उदाहरण
using System;
using System.Collections;
public class Demo {
public static void Main() {
SortedList list = new SortedList ();
list.Add("A", "Books");
list.Add("B", "Electronics");
list.Add("C", "Appliances");
list.Add("D", "Pet Supplies");
list.Add("E", "Clothing");
list.Add("F", "Footwear");
Console.WriteLine("Value associated with key E = "+list["E"]);
list["E"] = "HDD";
Console.WriteLine("Value associated with key E [Updated] = "+list["E"]);
}
} आउटपुट
यह निम्नलिखित आउटपुट देगा -
Value associated with key E = Clothing Value associated with key E [Updated] = HDD
उदाहरण
आइए एक और उदाहरण देखें -
using System;
using System.Collections;
public class Demo {
public static void Main() {
SortedList list = new SortedList ();
list.Add("A", "Books");
list.Add("B", "Electronics");
list.Add("C", "Appliances");
list.Add("D", "Pet Supplies");
list.Add("E", "Clothing");
list.Add("F", "Footwear");
Console.WriteLine("Value associated with key D = "+list["D"]);
}
} आउटपुट
यह निम्नलिखित आउटपुट देगा -
Value associated with key D = Pet Supplies