ListDictionary에서 지정된 키와 관련된 값을 가져오거나 설정하려면 코드는 다음과 같습니다. -
예
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
ListDictionary dict = new ListDictionary();
dict.Add("A", "Books");
dict.Add("B", "Electronics");
dict.Add("C", "Appliances");
dict.Add("D", "Pet Supplies");
dict.Add("E", "Clothing");
dict.Add("F", "Footwear");
Console.WriteLine("Value associated with key C = "+dict["C"]);
}
} 출력
이것은 다음과 같은 출력을 생성합니다 -
Value associated with key C = Appliances
예
다른 예를 살펴보겠습니다 -
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
ListDictionary dict = new ListDictionary();
dict.Add("A", "Books");
dict.Add("B", "Electronics");
dict.Add("C", "Appliances");
dict.Add("D", "Pet Supplies");
dict.Add("E", "Clothing");
dict.Add("F", "Footwear");
Console.WriteLine("Value associated with key C = "+dict["C"]);
dict["C"] = "HDD";
Console.WriteLine("Value associated with key C [Updated] = "+dict["C"]);
}
} 출력
이것은 다음과 같은 출력을 생성합니다 -
Value associated with key C = Appliances Value associated with key C [Updated] = HDD