ในการรับหรือตั้งค่าที่เกี่ยวข้องกับคีย์ที่ระบุใน 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