如何在 C# 中检查二维(或更多)维数组的大小?
我有:
double[,] table = new double[3,4];
如何检查该表的两种尺寸? table.Length
给我 12
这是表中元素的总数。
I have:
double[,] table = new double[3,4];
How to check both sizes of that table? table.Length
gives me 12
which is total number of elements in table.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
GetLength
方法。因此,
table.GetLength(0)
将返回 3,table.GetLength(1)
将返回 4。GetLength
的参数是零您想知道其长度的数组的基维。Use the
GetLength
method.So
table.GetLength(0)
will return 3 andtable.GetLength(1)
will return 4.The parameter for
GetLength
is the zero-based dimension of the array you want to know the length of.Table.GetLength(0);
为您提供 3Table.GetLength(1);
为您提供 4希望这会有所帮助。
Table.GetLength(0);
gives you 3Table.GetLength(1);
gives you 4Hope this helps.
获取长度?
参考
GetLength?
ref