获取或设置与 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