arraylist

  • Thread starter Thread starter Guest
  • Start date Start date
Is System.Collections.Arraylist a one dimensional array?
Thanks for your replies.

It isn't a one dimensional array itself, but conceptually it's similar,
and the implementation almost certainly contains a one dimensional
array. I'm not sure that's what you were after though - could you give
more detail about what you need to know?
 
Thanks Jon. I am trying to see if I can dynamically resize
my multi dimensional array. My array is not an instance of
the Array class (to my beginner knowledge). When my array
is resized, I don't want to lose the existing data. So I
am trying accomplish something that is done by VB Redim.
I am struggling at this point...
 
Hello,

Jon provided an answer to the exact same question yesterday. I do not
know if you posted it or not, but this is what Jon Skeet wrote:

"No - you basically have to create a new array, and then use Array.Copy
or Array.CopyTo to copy the elements from the old one into the new one.
That's what VB.NET's Redim does under the covers anyway, I believe."

Hope this helps,

//Andreas
 
Hi Jon,
I am actually wondering how to copy the contents of a
multi dimensional array to another multi dimensional
array. Thanks for your help.
 
Hi all
Is System.Collections.Arraylist a one dimensional array?
Thanks for your replies.

OK so everyone is pretty much going to say "YES" to this question, but
keep in mind that an ArrayList can store ANY type of object, even
another ArrayList. So you could have an ArrayList of ArrayLists to
create a two-dimensional structure.

So conceptually you might have something like this:

ArrayList ---> ArrayList[0]
ArrayList[1]
ArrayList[2]
ArrayList[3]

ArrayList[0] ---> 18
22
99


ArrayList[1] ---> 45
29
33

etc... etc.. etc...

But keep in mind that you CANNOT reference these like ArrayList[0][0].
You have to cast the first reference into an ArrayList object. So if
you wanted to access the '33' above, it would be:

(int)(((ArrayList)ArrayListVar[1])[2])

and even that is a bit dangerous unless you know for certain that the
first reference will be an ArrayList (you should be able to guarantee
this in simple situations.)

-mdb
 
Thanks Jon. I am trying to see if I can dynamically resize
my multi dimensional array. My array is not an instance of
the Array class (to my beginner knowledge). When my array
is resized, I don't want to lose the existing data. So I
am trying accomplish something that is done by VB Redim.
I am struggling at this point...

Your array *is* actually an instance of Array - all arrays are. It's
just rare to use the Array type directly. You can still use Array.Copy
for multi-dimensional arrays - have a look at the docs to see exactly
what it does in that case.
 
Michael Bray said:
OK so everyone is pretty much going to say "YES" to this question

I hope they don't, as an ArrayList *isn't* an array. It may fulfill the
same kind of role, but it most definitely isn't actually an array.
 
Back
Top