检查SortedList对象是否在C#中同步
要检查SortedList对象是否同步,代码如下-
示例
using System;
using System.Collections;
public class Demo {
public static void Main() {
SortedList list = new SortedList();
list.Add("1", "One");
list.Add("2", "Two");
list.Add("3", "Three");
list.Add("4", "Four");
list.Add("5", "Five");
list.Add("6", "Six");
list.Add("7", "Seven");
list.Add("8", "Eight");
Console.WriteLine("Key and Value of SortedList....");
foreach(DictionaryEntry k in list )
Console.WriteLine("Key: {0}, Value: {1}", k.Key , k.Value );
Console.WriteLine("Is the SortedList having the value? "+list.ContainsValue("Five"));
SortedList sortedList = SortedList.Synchronized(list);
Console.WriteLine("Is the SortedList synchronized? = "+sortedList.IsSynchronized);
}
}输出结果
这将产生以下输出-
Key and Value of SortedList.... Key: 1, Value: One Key: 2, Value: Two Key: 3, Value: Three Key: 4, Value: Four Key: 5, Value: Five Key: 6, Value: Six Key: 7, Value: Seven Key: 8, Value: Eight Is the SortedList having the value? True Is the SortedList synchronized? = True
示例
让我们看另一个例子-
using System;
using System.Collections;
public class Demo {
public static void Main() {
SortedList list = new SortedList();
list.Add("1", "One");
list.Add("2", "Two");
list.Add("3", "Three");
list.Add("4", "Four");
list.Add("5", "Five");
list.Add("6", "Six");
list.Add("7", "Seven");
list.Add("8", "Eight");
Console.WriteLine("Key and Value of SortedList....");
foreach(DictionaryEntry k in list )
Console.WriteLine("Key: {0}, Value: {1}", k.Key , k.Value );
Console.WriteLine("Is the SortedList having the value? "+list.ContainsValue("Ten"));
Console.WriteLine("Is the SortedList synchronized? = "+list.IsSynchronized);
}
}输出结果
这将产生以下输出-
Key and Value of SortedList.... Key: 1, Value: One Key: 2, Value: Two Key: 3, Value: Three Key: 4, Value: Four Key: 5, Value: Five Key: 6, Value: Six Key: 7, Value: Seven Key: 8, Value: Eight Is the SortedList having the value? False Is the SortedList synchronized? = False
热门推荐
10 新房开工吉日祝福语简短
11 直播祝福语老师文案简短
12 祖国生日祝福语简短英文
13 周末祝福语正能量简短
14 特别的端午祝福语简短
15 小红书平安祝福语简短
16 朋友花篮开业祝福语简短
17 新年简短的祝福语爱情
18 信件告别祝福语大全简短