如何在 VB.net 中找到二维数组中的行数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6870424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:46:29  来源:igfitidea点击:

How find row count in a 2D array in VB.net?

.netvb.net

提问by Yugal Jindle

How to find the number of horizontal rows in a 2D array ?

如何找到二维数组中的水平行数?

I have :

我有 :

   Dim i(,) As Integer = {{2, 5, 6, 7}, {32, 5, 4, 2}}

Find the number of rows in i ?

找出 i 中的行数?

For example :

例如 :

 // Here, array i has 2 sets of data i.e. 2 rows
 // set1 = {2,5,6,7} and set2 = {32,5,4,2}
 // So, I want the number of sets i.e 2 in this case !

Please help !

请帮忙 !

回答by Matti Virkkunen

The GetLengthmethod can be used to find out the length of any dimension of the array.

对GetLength方法可用于找出该阵列的任何尺寸的长度。

回答by Samuel Lopes

I believe this code should work for you:

我相信这段代码应该适合你:

Dim array(56,67) As Integer 'Example array'
Dim x_axis As Integer = array.GetLength(0)-1 'To find out number of dimensions on the x'
Dim y_axis As Integer = array.GetLength(1)-1 'To find out number of dimensions on the y'

回答by Vijay Mathapati

GetLength(0)will give the number of rows present in 2D array

GetLength(0)将给出二维数组中存在的行数