我是一个非常新的程序员,一直在努力编写一个可以接受任何 2D 数组并用 1 到 15 之间的随机整数填充它的方法。我相信我成功地正确构建了我的方法,但我似乎看不到然后如何调用我的方法来填充我在 main 中创建的数组。(我会直接将其填入 main 中,但我也在尝试练习方法。)这是我到目前为止的代码。我感谢你们能够给我的任何帮助,谢谢!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Homework2
{
class Program
{
static void Main(string[] args)
{
int[,] myArray = new int[5,6];
}
public int[,] FillArray (int i, int j)
{
Random rnd = new Random();
int[,] tempArray = new int[,]{};
for (i = 0; i < tempArray.GetLength(0); i++)
{
for (j = 0; j < tempArray.GetLength(1); j++)
{
tempArray[i, j] = rnd.Next(1, 15);
} …Run Code Online (Sandbox Code Playgroud)