[.net] Multidimensional Arrays
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
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.
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)
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.
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.
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...
I'm not really familiar with System.Collections, though, so I might be wrong...
Here's an article that shows what I mean...
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++.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement