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

  • 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 `int`s 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 `int`s or 50 `int[]`s: use an array, which is what [@MarcGravell's answer](https://stackoverflow.com/a/59993508/150605) does. As for the "array pointer" you mention in the title, that's essentially what [jagged arrays](https://docs.microsoft.com/dotnet/csharp/programming-guide/arrays/jagged-arrays) are. – Lance U. Matthews Jan 30 '20 at 20:25

1 Answers1

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];
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900