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