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