T
Tad Marshall
Hi,
I'm reading about arrays in VB.NET and I seem to have a few options for my
data structure. I need a multi-dimensional array of structures, and my
first thought was
Public Structure myStr
Public part1 as Integer
Public part2 as Integer
End Structure
Dim simpleWay(2, 2, 2, 2, 2, 100) As myStr
This seems workable, but I usually won't actually have 100 of these things,
that's just the maximum I'll permit.
So, I read about jagged arrays, and I think I could do
Dim jaggedWay(2, 2, 2, 2, 2)() as myStr
except that the last dimension will grow and shrink at runtime and I can't
find any examples of code doing this or figure out how to get ReDim to do it
for me.
Another possibility is to use an array of Collections, like
Dim collectionWay(2, 2, 2, 2, 2) as Collection
' Should be a loop to create all elements, but I'll just do one ...
collectionWay(0, 0, 0, 0, 0) = New Collection
collectionWay(0, 0, 0, 0, 0,).Add(myStrInstance)
I think that I could equally well use ArrayList instead of Collection, that
would work more or less the same way as using Collections.
Is the jagged array approach even possible for me? The "simple" way has some
appeal since it uses early binding, but it may be pretty wasteful in memory.
So long as I don't run out of memory, I'm not sure how much I care. The
Collection or ArrayList approach seems both more clumsy to code and more
elegant in addressing my varying length requirements.
Any suggestions? Thanks!
Tad
I'm reading about arrays in VB.NET and I seem to have a few options for my
data structure. I need a multi-dimensional array of structures, and my
first thought was
Public Structure myStr
Public part1 as Integer
Public part2 as Integer
End Structure
Dim simpleWay(2, 2, 2, 2, 2, 100) As myStr
This seems workable, but I usually won't actually have 100 of these things,
that's just the maximum I'll permit.
So, I read about jagged arrays, and I think I could do
Dim jaggedWay(2, 2, 2, 2, 2)() as myStr
except that the last dimension will grow and shrink at runtime and I can't
find any examples of code doing this or figure out how to get ReDim to do it
for me.
Another possibility is to use an array of Collections, like
Dim collectionWay(2, 2, 2, 2, 2) as Collection
' Should be a loop to create all elements, but I'll just do one ...
collectionWay(0, 0, 0, 0, 0) = New Collection
collectionWay(0, 0, 0, 0, 0,).Add(myStrInstance)
I think that I could equally well use ArrayList instead of Collection, that
would work more or less the same way as using Collections.
Is the jagged array approach even possible for me? The "simple" way has some
appeal since it uses early binding, but it may be pretty wasteful in memory.
So long as I don't run out of memory, I'm not sure how much I care. The
Collection or ArrayList approach seems both more clumsy to code and more
elegant in addressing my varying length requirements.
Any suggestions? Thanks!
Tad