C#如何遍历Dictionary
程序员文章站
2022-06-05 14:19:47
本文实例为大家分享了c#如何遍历dictionary的具体代码,供大家参考,具体内容如下
using system;
using system.collecti...
本文实例为大家分享了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的方法,谢谢大家的阅读。