0

// I have to declare 50 arrays to declare that range from 1 to 50 with the following syntax:

la_Array_1;
la_Array_2;
la_Array_3;

la_Array_50;

// Then based on a value of the an integer value called li_Choose_Array I want to access that specific array.

// For example if li_Choose_Array is equal to 17 then I want access la_Array_17.

// My questions are, how would I declare the 50 arrays dynamically so that I do not have to manually enter each declaration.

// And secondly, how would I access the la_Array_17 when my li_Choose_Array value is equal to 17?

TIA

1
  • I think the duplicates answer exactly what was asked but not what you (probably) really want (though I'm sure there's duplicates for that, too). If you had 50 ints to store instead of declaring 50 variables you'd use an array of length 50, right? Well, it's the same thing whether it's 50 ints or 50 int[]s: use an array, which is what @MarcGravell's answer does. As for the "array pointer" you mention in the title, that's essentially what jagged arrays are. Commented Jan 30, 2020 at 20:25

1 Answer 1

3

why not create an array of arrays, i.e. if la_Array_1 is a string[], then instead have:

string[][] la_Arrays = new string[50][];

Then to access the 17'th element, remembering that arrays are 0-based:

string[] arr = la_Arrays[16];

or in general:

string[] arr = la_Arrays[li_Choose_Array - 1];
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.