0

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.

1 Answer 1

1

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:

outArr

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.