Row Length in a rectangular array
Row Length in a rectangular array
How do I find the row length of an rectangular array I have a class that wraps a 2-dimentional array and would like to be able to supply the row and column length as proporties. My idea is to set the value of these proporties in the class constructor based on the given values hold by a rectangular array. Alternatively I could make the constructor take a jagged array instead. If that is nessesary, I am beginning to loose the porpose of using a rectangular array.
| | int[,] rectangularArray; int rowLength = .length |
With a jagged array it is quite simple:
| | int[][] jaggedArray; int rowLength = jaggedArray[0].Length |
Are there any performance concerns that shoul be taken into account when choosing between jagged and rectangular arrays
Row Length in a rectangular array
Calve
int[,] rectangularArray;
you will declare the length of a "row" at some later point, and retrieve the length associated with any subscript with
rectangularArray.GetLength(i);
where "i" is 'A zero-based dimension of the Array whose length needs to be determined.'
Re performance: it depends on your application. Measure if it's really a concern.
eri
I read an article on .Net performance enhancements and it showed jagged arrays to be significantly faster than rectangular arrays. I had some speed critical code that I converted and I realized a significant improvement. That was .Net 1.0, the situation could be different 1.1 and/or 2.0.