Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hai all,
How do i set number of columns of an multidimentional array at runntime ?
Posted

Hi rahulrcn,

You can take the number of rows and the number of columns from the user and store it in Columns and Rows variables then :

int[,] Array = new int[Rows, columns];


I hope this help,
:)
 
Share this answer
 
There is a good description with examples on MSDN[^]

But:
int[,] myArray = new int[myRowsCount, myColumnsCount];
Note that is you want the array populated with items more complex than ints, floats, etc., (such as your own classes) that you must iterate through the array and provide the references before you use them, or provide an initializer when you declare the array. The link gives examples of this too.

Also note that multi-dimensional arrays get very big, very fast. For two dimensions, it is a square law. For three it's a cubic, and so on.
 
Share this answer
 
Comments
ambarishtv 21-May-11 4:13am    
my 5 for valuable info

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900