在 C# 中獲取包含 ListDictionary 中值的 ICollection
要獲取包含 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.Values;
foreach(String s in col){
Console.WriteLine(s);
}
}
}輸出
這將產生以下輸出 −
Laptop Tablet Desktop Speaker Earphone Headphone
示例
讓我們看另一個示例 −
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.Values;
foreach(String s in col){
Console.WriteLine(s);
}
}
}輸出
這將產生以下輸出 −
Tom John Kevin Tim
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言
C++
C#
MongoDB
MySQL
Javascript
PHP