[.net] Multidimensional Arrays

Started by
4 comments, last by _DarkWIng_ 18 years, 10 months ago
Is there any easy way to use dynamic multidimensional arrays in C#? I know you can make arrayLists of arrayLists but that would involve a bunch of casts and unweildy code. Is there an easier way to do it? -Shane
Advertisement
int j = 10;int[,] fa = new int[j,j];orint[][] ra = new int[j][];for(int i = 0; i < ra.Length; ++i) {	ra = new int[j];}


take your pick, jagged vs square.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Alright, I was also wondering how to resize a multidimensional array (square).
It looks like the array class only works for single dimensional arrays.

-Shane (.NET rookie)
A jagged array is an array of arrays. So, you can still use the Array class on it and its elements.

There's also the System.Collections.ArrayList class, which is a one-dimensional array that resizes itself. If you have an ArrayList whose elements were all ArrayLists, that will work as a multidimensional, automatically resized array.
--------------Trans2D - 2D library for C# / Managed DirectX
J/W, but couldn't you also create a custom collection that works like an ArrayList, but is implemented with your custom type? That way you could return a double or MyClass instead of System.Object.

I'm not really familiar with System.Collections, though, so I might be wrong...

Here's an article that shows what I mean...
~del
Quote:Original post by Del Snd of Thndr
J/W, but couldn't you also create a custom collection that works like an ArrayList, but is implemented with your custom type? That way you could return a double or MyClass instead of System.Object.

You don't need to write it because .NET 2.0 already includes it. They are called generics and they look a little bit like templates in C++.
You should never let your fears become the boundaries of your dreams.

This topic is closed to new replies.

Advertisement