獲取或設定與 C# 中 ListDictionary 中指定鍵相關聯的值
要獲取或設定與 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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP