创建一个Dictionary<int, string>泛型集合,向集合中添加三组元素,使用foreach循环遍历集合中的元素。
3条回答 默认 最新
threenewbee 2023-11-20 00:57关注using System; using System.Linq; using System.Collections.Generic; class Program { public static void Main(string[] args) { var dict = new Dictionary<int, string>() { { 1, "a" }, { 2, "b" }, { 3, "c"} }; foreach (var item in dict) Console.WriteLine($"{item.Key}, {item.Value}"); } }本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报