【发布时间】:2019-03-11 03:42:27
【问题描述】:
我应该做一个列表字典来显示不同人的测试分数,最终结果应该是这样的:
目前我的代码看起来像这样,我遇到的问题是数字打印了 3 次,而不是显示的一次。请帮忙!
static void Main(string[] args)
{
Random myRandomGenerator = new Random();
Dictionary<string, List<int>> table = new Dictionary<string, List<int>>();
table["Meuleveld, McKenzie"] = new List<int>(){ myRandomGenerator.Next(60, 100), myRandomGenerator.Next(60,100), myRandomGenerator.Next(60,100)};
table["McGuire, Matthew"] = new List<int>(){ myRandomGenerator.Next(60, 100), myRandomGenerator.Next(60, 100), myRandomGenerator.Next(60, 100) };
table["Anderton, Paitlyn"] = new List<int>(){ myRandomGenerator.Next(60, 100), myRandomGenerator.Next(60, 100), myRandomGenerator.Next(60, 100) };
table["Moore, Jeni"] = new List<int>(){ myRandomGenerator.Next(60, 100), myRandomGenerator.Next(60, 100), myRandomGenerator.Next(60, 100) };
foreach (string name in table.Keys)
{
List<int> value = table[name];
foreach (int valueList in value)
{
Console.WriteLine($"{name} exam scores: {valueList}, {valueList}, {valueList}");
Console.ReadKey();
}
}
}
【问题讨论】:
-
请以文本形式显示预期结果和以文本形式显示实际结果。
-
逐行调试。对于每个
name,第二个foreach输入了多少次?你认为这是为什么? -
为什么这个问题的代码被删掉了?
-
@brandnewcoder - 如果您还有其他问题,请提交一个新问题,而不是编辑这个问题。
标签: c# list dictionary