检查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("Three"));
Console.WriteLine("The SortedList object has a fixed size? = "+list.IsFixedSize);
}
}输出结果
这将产生以下输出-
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 The SortedList object has a fixed size? = False
示例
让我们看另一个例子-
using System;
using System.Collections;
public class Demo {
public static void Main(){
SortedList list = new SortedList();
list.Add("1", "John");
list.Add("2", "Tim");
list.Add("3", "Karl");
list.Add("4", "Gary");
list.Add("5", "Katie");
Console.WriteLine("Key and Value of SortedList....");
foreach(DictionaryEntry k in list )
Console.WriteLine("Key: {0}, Value: {1}", k.Key , k.Value );
Console.WriteLine("The SortedList object has a fixed size? = "+list.IsFixedSize);
}
}输出结果
这将产生以下输出-
Key and Value of SortedList.... Key: 1, Value: John Key: 2, Value: Tim Key: 3, Value: Karl Key: 4, Value: Gary Key: 5, Value: Katie The SortedList object has a fixed size? = False
热门推荐
10 日语送考祝福语简短
11 宝宝新生入学祝福语简短
12 生日牌祝福语英语简短
13 农民朋友发财祝福语简短
14 姐姐生日祝福语漂亮简短
15 周年庆典祝福语致辞简短
16 高考送考祝福语简短
17 浪漫的生日祝福语简短
18 婚礼西装祝福语简短男士