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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP