【发布时间】:2015-12-13 14:57:41
【问题描述】:
我是一个非常新的程序员,并且一直在努力编写一种可以采用任何二维数组并用 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);
}
}
return tempArray;
}
}
}
【问题讨论】:
标签: c# arrays multidimensional-array methods