在运行时设置多维数组的列号 [英] Setting column number of multidimensional array in run time

查看:73
本文介绍了在运行时设置多维数组的列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
如何在运行时设置多维数组的列数?

Hai all,
How do i set number of columns of an multidimentional array at runntime ?

推荐答案

嗨rahulrcn,

您可以从用户那里获取行数和列数,并将其存储在ColumnsRows变量中,然后:

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,
:)


There is a good description with examples on MSDN[^]

But:
int[,] myArray = new int[myRowsCount, myColumnsCount];

请注意,您是否要在数组中填充比int,float等更复杂的项目(例如您自己的类),因此您必须遍历数组并提供引用,然后再使用它们或提供初始化程序当您声明数组时.该链接也提供了此示例.

还要注意,多维数组变得非常大,非常快.对于二维,这是平方律.对于三个,它是立方,依此类推.

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.


这篇关于在运行时设置多维数组的列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆