检查SortedList在C#中是否为只读
要检查SortedList是否为只读,代码如下-
示例
using System;
using System.Collections;
public class Demo {
public static void Main(String[] args) {
SortedList list = new SortedList();
list.Add("One", "IT");
list.Add("Two ", "Operations");
list.Add("Three", "Marketing");
list.Add("Four", "Purchase");
list.Add("Five", "Sales");
list.Add("Six", "Finance");
Console.WriteLine("SortedList elements...");
foreach(DictionaryEntry d in list) {
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("\nList of values...SortedList");
IList col = list.GetValueList();
foreach(string res in col) {
Console.WriteLine(res);
}
Console.WriteLine("\nSortedList is read-only? = "+list.IsReadOnly);
}
}输出结果
这将产生以下输出-
SortedList elements... Five Sales Four Purchase One IT Six Finance Three Marketing Two Operations List of values...SortedList Sales Purchase IT Finance Marketing Operations SortedList is read-only? = False
示例
让我们看另一个例子-
using System;
using System.Collections;
public class Demo {
public static void Main(String[] args) {
SortedList list = new SortedList();
list.Add("One", "Finance");
list.Add("Two", "Marketing");
list.Add("Three", "Sales");
list.Add("Four", "Purchase");
list.Add("Five", "Operations");
list.Add("Six", "IT");
Console.WriteLine("SortedList elements...");
foreach(DictionaryEntry d in list) {
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("\nIndex at key One = "+list.IndexOfKey("One"));
ICollection col = list.Keys;
Console.WriteLine("\nCollection of Keys...");
foreach(string res in col)
Console.WriteLine(res);
Console.WriteLine("\nSortedList is read-only? = "+list.IsReadOnly);
}
}输出结果
这将产生以下输出-
SortedList elements... Five Operations Four Purchase One Finance Six IT Three Sales Two Marketing Index at key One = 2 Collection of Keys... Five Four One Six Three Two SortedList is read-only? = False
热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短