C#中SortedList类的Keys属性是什么?
使用C#中SortedList类的keys属性获取SortedList中的键。我们首先使用元素设置了SortedList属性。
SortedList sl = new SortedList();
sl.Add("ST0", "One");
sl.Add("ST1", "Two");
sl.Add("ST2", "Three");
sl.Add("ST3", "Four");
sl.Add("ST4", "Five");
sl.Add("ST5", "Six");
sl.Add("ST6", "Seven");现在使用keys属性获取键。
ICollection key = sl.Keys;
以下是实现SortedList类的keys属性的完整代码。
示例
using System;
using System.Collections;
namespace Demo {
class Program {
static void Main(string[] args) {
SortedList sl = new SortedList();
sl.Add("ST0", "One");
sl.Add("ST1", "Two");
sl.Add("ST2", "Three");
sl.Add("ST3", "Four");
sl.Add("ST4", "Five");
sl.Add("ST5", "Six");
sl.Add("ST6", "Seven");
ICollection key = sl.Keys;
foreach (string k in key) {
Console.WriteLine(k);
}
}
}
}输出结果
ST0 ST1 ST2 ST3 ST4 ST5 ST6
热门推荐
10 恭喜祝福语回复语句简短
11 旅行前祝福语简短英语
12 妹妹考上军校祝福语简短
13 企业国庆问候祝福语简短
14 2026年祝福语大全简短
15 顺利毕业家人祝福语简短
16 小升初考试后祝福语简短
17 干老师祝福语朋友简短
18 经典新婚祝福语英文简短