我正在学习 C# 并且我创建了一个代码来List使用for循环向 a 添加随机数。
class Program
{
static void Main(string[] args)
{
Random numberGen = new Random();
List<int> randomNum = new List<int>();
for (int i = 0; i < 10; i++)
{
randomNum.Add(numberGen.Next(1, 100));
}
for (int i = 0; i < randomNum.Count; i++)
{
Console.WriteLine(randomNum[i]);
}
Console.ReadKey();
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有一种方法可以使用类似的方法将随机数添加到数组中?