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