我想从下面显示的QandA_Dictionary打印每个键和值,但我不断获取System.int32 []而不是我列出的实际值。有人能指出我解决这个问题的正确方向吗?如何从此数组中打印字典值而不是System.int32 []?
using System;
using System.Collections;
using System.Collections.Generic;
namespace DictionaryPractice
{
class MainClass
{
public static void Main(string[] args)
{
Dictionary<string, int[]> QandA_Dictionary = new Dictionary<string, int[]>();
QandA_Dictionary.Add("What is 1 + 1?", new int[] { 1, 2, 3, 4 });
QandA_Dictionary.Add("What is 1 + 2?", new int[] { 1, 2, 3, 4 });
QandA_Dictionary.Add("What is 1 + 3?", new int[] { 1, 2, 3, 4 });
QandA_Dictionary.Add("What is 1 + 4?", new int[] { 2, 3, 4, 5 });
foreach (var pair in QandA_Dictionary)
{
Console.WriteLine("{0},{1}", pair.Key, pair.Value);
}
Console.ReadKey();
}
}
}
太棒了!这正是我想要做的。我现在将讨论一些实际的逻辑。它似乎只是一些语法类型的东西导致我的问题。我是编程和本网站的新手。我会等5分钟,然后给你一个复选标记。其他人在你离开后2分钟回答,所以我在等待我是否应该遵守一些现场道德规范,或者只是先以先到先得的方式给予奖励。我很快就会掌握所有这一切。再次感谢芽。如果我的回应与本网站的运作不符,我下次将忽略“华夫饼”。 – sean