How would I create a series of arrays?

cfisher440

Well-known member
Joined
Oct 11, 2005
Messages
73
Programming Experience
1-3
How would I create a series of arrays (each one needs a different name) based off an integer value?

Example.
If the integer value is 3 then create arrays
r1, r2, r3 as string() = new string() {}

so if value is five then create r1, r2, r3, r4, and r5.

How would I programmatically do this?
 
You can't do that, but you can create an array of arrays that you can access by index.
VB.NET:
Dim[SIZE=2] ar() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Array[/SIZE]
If all the arrays are equal size and type you can also use a single two-dimensional array.
VB.NET:
Dim[SIZE=2] ar(,) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] String[/SIZE]
You can also use a list collection containing lists of strings
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] lists [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] List([/SIZE][SIZE=2][COLOR=#0000ff]Of[/COLOR][/SIZE][SIZE=2] List([/SIZE][SIZE=2][COLOR=#0000ff]Of [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2]))[/SIZE]
If naming each element is required you need to create a custom class type that have both a name and an array/list, very basic like this:
VB.NET:
[SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] NamedStringList[/SIZE]
[SIZE=2][COLOR=#0000ff] Public[/COLOR][/SIZE][SIZE=2] name [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] Public[/COLOR][/SIZE][SIZE=2] strings [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] List([/SIZE][SIZE=2][COLOR=#0000ff]Of [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE]
Then create a list collection of this so:
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] nsl [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] List([/SIZE][SIZE=2][COLOR=#0000ff]Of[/COLOR][/SIZE][SIZE=2] NamedStringList)[/SIZE]
 
Back
Top