I have checked a previous question similar however the provided solution did not work for me, or perhaps I am overlooking something. How to return a jagged array
My code is as follows:
class Grids
{
int[][] grid;
public grid[][] MakeGrid()
{
grid = new int [4][];
for (int i = 0; i < 4; i++)
{
grid[i] = new int[4] {0,0,0,0};
for (int a = 0; a < 4; a++)
{
Console.Write(grid[i][a]);
}
Console.WriteLine();
}
return;
}
}
The error returned is as follows:
.Grids.grid' is a 'field' but is used like a 'type'
Some minor adjustments required in your MakeGrid
method:
public int[][] MakeGrid()
{
grid = new int[4][];
for (int i = 0; i < 4; i++)
{
grid[i] = new int[4] { 0, 0, 0, 0 };
for (int a = 0; a < 4; a++)
{
Console.Write(grid[i][a]);
}
Console.WriteLine();
}
return grid;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.