Multidimensional arrays? any other options?

  • Thread starter Thread starter Naomi
  • Start date Start date
N

Naomi

Hi there,

Just wondering, if there is any way to have a dynamic / unspecified size of
an array? It obviously needs to be updated, deleted etc. The only way I
thought is by making the array massive at the start? Any other ideas?
Apparently Hashtable, ArrayList etc are useless as they all take one
dimension. :( Please help me!

Thanks,
Naomi
 
1. You can put hashtables into hastables (to any depth you want) to get
multi-dimensional-hashtables.
2. The same, of course, applies to ArrayLists.
3. ArrayList's don't really "grow": If you break the size limits of an
ArrayList, it will allocate a bigger block of memory, copy all the data, and
free the old block, this is merely hidden away inside the class - you can of
course do the same in your code.
4. If you really need a the data structure that can increase its size
without reallocation, you'll have to use a linked list, but that will
probably not give you any performance benefit unless you frequently
insert/remove items in the beginning/middle of your list. (AFAIK garbage
collectors don't like linked lists)

Hope this helps

Niki
 
I feel your pain. C# doesn't have a way of defining a multi-dimential
dynamic unspecified size array. It is one the worst limitations that I have
come across in C#. I think they definitely need to address this problem in
the next version of C#.

Best of luck,

Amadelle
 
Amadelle said:
I feel your pain. C# doesn't have a way of defining a multi-dimential
dynamic unspecified size array. It is one the worst limitations that I have
come across in C#. I think they definitely need to address this problem in
the next version of C#.

It's not really a C# limitation - it's a .NET limitation, and one which
naturally comes from arrays of all types being fixed in size. That is a
limitation in some ways, but a great benefit in others (notably
performance - I believe various optimisations can be performed if you
know that the size isn't going to change).

Generics will help to some extent, in terms of having an ArrayList of
ArrayLists without having to cast all over the place. It still won't be
*really* straightforward, but better than it is now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top