【发布时间】:2018-04-12 07:49:43
【问题描述】:
//dice throws to arrays
int throws = 1;
int[] oneDice = new int[throws];
int[,] twoDice = new int[throws,throws];
Console.WriteLine("Number of throws: ");
throws = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Trows one dice "+throws+" times: ");
for (int i = 0; i < throws; i++)
{
Random random = new Random();
oneDice[i] = random.Next(6);
Console.WriteLine(oneDice[i]);
}
它说我的数组 oneDice 超出范围,但我不明白为什么.. 请帮我弄清楚。
【问题讨论】:
-
您正在创建长度为 1 的数组。您应该在创建数组之前阅读投掷次数。