這個也是很常用,也來記錄一下。
參考:http://msdn.microsoft.com/zh-tw/library/5tbh8a42.aspx
01 | using System.Collections; |
02 | namespace KeyValuePairTest { |
03 | class Program { |
04 | private static Dictionary<string, string> _DicList; |
05 | static void Main(string[] args) { |
06 | _DicList = new Dictionary<string, string>(); |
07 | _DicList.Add("s1", "test1"); |
08 | _DicList.Add("s2", "test2"); |
09 | _DicList.Add("s3", "test3"); |
10 | |
11 | foreach (KeyValuePair<string, string> item in _DicList) { |
12 | Console.WriteLine(item.Value); |
13 | } |
14 | |
15 | Console.ReadKey(); |
16 | } |
17 | } |
18 | } |
輸出結果:
三小俠 小弟獻醜,歡迎指教
本文介绍如何在C#中创建字典并将键值对进行遍历,包括实例代码演示。
1714

被折叠的 条评论
为什么被折叠?



