获取或设置与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
热门推荐
10 开业贺卡祝福语简短高级
11 新年英文祝福语简短创意
12 八一祝福语简短文字
13 红包祝福语简短10字
14 10岁高考祝福语简短
15 岁月祝福语简短10字
16 拜年祝福语英文长句简短
17 巧克力情侣祝福语大全简短
18 新娘祝福语诗词精选简短