0

What is the most efficient to add items to a multi-dimensional array where you don't know the item count at the start?

1
  • 2
    Use a List<List<T>>. Arrays are designed to start with a fixed size; lists are designed to be able to grow. Otherwise you have to resize the array manually. Commented Mar 6, 2015 at 17:49

1 Answer 1

2

You can use Array.GetLength method to get lenght of each dimension, then you can just populate your array using a simple for loop.

For example:

for(int x = 0; x < array.GetLength(0); x++)
{
     for(int y = 0; y < array.GetLength(1); y++)
     {
          array[x,y] = "bla,bla...";
     }
}
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.