获取包含 ListDictionary 中的键的 ICollection,C#
获取包含 ListDictionary 中键的 ICollection 的代码如下所示 −
示例
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main(){
ListDictionary listDict = new ListDictionary();
listDict.Add("1", "Laptop");
listDict.Add("2", "Tablet");
listDict.Add("3", "Desktop");
listDict.Add("4", "Speaker");
listDict.Add("5", "Earphone");
listDict.Add("6", "Headphone");
ICollection col = listDict.Keys;
foreach(String s in col){
Console.WriteLine(s);
}
}
}输出
这会产生以下输出 −
1 2 3 4 5 6
示例
我们来看另一个示例 −
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main(){
ListDictionary listDict = new ListDictionary();
listDict.Add("A", "Tom");
listDict.Add("B", "John");
listDict.Add("C", "Kevin");
listDict.Add("D", "Tim");
ICollection col = listDict.Keys;
foreach(String s in col){
Console.WriteLine(s);
}
}
}输出
这会产生以下输出 −
A B C D
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP