使用C#中的指定键获取或设置HybridDictionary中的值
要使用指定的键获取或设置HybridDictionary中的值,代码如下-
示例
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
HybridDictionary myDict = new HybridDictionary();
myDict.Add("1", "Tablet");
myDict.Add("2", "Desktop");
myDict.Add("3", "Speakers");
myDict.Add("4", "Laptop");
myDict.Add("5", "Notebook");
myDict.Add("6", "Ultrabook");
myDict.Add("7", "HDD");
myDict.Add("8", "SDD");
Console.WriteLine("Value at key 5 = "+myDict["5"]);
}
}输出结果
这将产生以下输出-
Value at key 5 = Notebook
示例
让我们看另一个例子-
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
HybridDictionary myDict = new HybridDictionary();
myDict.Add("1", "Tablet");
myDict.Add("2", "Desktop");
myDict.Add("3", "Speakers");
myDict.Add("4", "Laptop");
myDict.Add("5", "Notebook");
myDict.Add("6", "Ultrabook");
myDict.Add("7", "HDD");
myDict.Add("8", "SDD");
Console.WriteLine("Value at key 5 = "+myDict["5"]);
myDict["5"] = "Smart Watches";
Console.WriteLine("Value at key 5 [UPDATED] = "+myDict["5"]);
}
}输出结果
这将产生以下输出-
Value at key 5 = Notebook Value at key 5 [UPDATED] = Smart Watches
示例
让我们看另一个例子-
using System;
using System.Collections;
public class Demo {
public static void Main() {
Queue queue = new Queue();
queue.Enqueue(100);
queue.Enqueue(200);
queue.Enqueue(300);
queue.Enqueue(400);
queue.Enqueue(500);
Console.WriteLine("Queue...");
foreach(Object ob in queue) {
Console.WriteLine(ob);
}
Console.WriteLine("Count of elements = "+queue.Count);
Console.WriteLine("Synchronize access...");
lock(queue.SyncRoot) {
foreach(Object ob in queue) {
Console.WriteLine(ob);
}
}
}
}输出结果
这将产生以下输出-
Queue... 100 200 300 400 500 Count of elements = 5 Synchronize access... 100 200 300 400 500
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短