C#若何遍歷Dictionary。本站提示廣大學習愛好者:(C#若何遍歷Dictionary)文章只能為提供參考,不一定能成為您想要的結果。以下是C#若何遍歷Dictionary正文
本文實例為年夜家分享了C#若何遍歷Dictionary的詳細代碼,供年夜家參考,詳細內容以下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _02DictionaryIterator
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("開端遍歷聚集");
IteratorDictionary();
Console.ReadKey();
}
/// <summary>
/// 遍歷Dictionary聚集
/// </summary>
private static void IteratorDictionary()
{
Dictionary<string, int> dictionary = new Dictionary<string, int>
{
{"張三", 1},
{"李四", 2},
{"王五", 3},
{"趙六", 4},
{"田七", 5}
};
foreach (KeyValuePair<string, int> keyValuePair in dictionary)
{
Console.WriteLine("key:{0}\tvalue:{1}", keyValuePair.Key, keyValuePair.Value);
}
}
}
}
後果圖:

以上就是本文的全體內容,教會年夜家C#遍歷Dictionary的辦法,感謝年夜家的浏覽。