Reputation: 9080
I currently want a 2D array (4,4) to look like this:
outArr = new string[4, 4]
{
{"0","0","0","0" },
{"0","0","0","0" },
{"0","0","0","0" },
{"0","0","0","0" }
};
However, I'm unsure of how to do with in code where the array sizes could be dynamic at runtime (i.e. 3,5 or 10,10)
I found this example on how to create the array dynamically (for an int array):
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
But I want to know how to create the elements "0" in my array dynamically.
Upvotes: 0
Views: 43
Reputation: 117027
Try this:
var r = 7;
var c = 4;
var outArr = new string[r, c];
for (var i = 0; i < r; i++)
for (var j = 0; j < c; j++)
outArr[i, j] = "0";
That gives me:
Upvotes: 1