在 C# 中獲取或設定 StringDictionary 中與指定鍵關聯的值
如下所示,獲取或設定 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
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP