[英]how to get the count of items in two dimensional array
I'm trying to get the count of items in one of the dimensions of a 2 dim array. 我试图获取2暗数组的维度之一中的项目数。
For example, a simplistic version of my array looks like this: 例如,我的数组的简化版本如下所示:
my_array(0)(1) = "a"
my_array(0)(2) = "b"
my_array(0)(3) = "c"
I'm trying to find out the count of items in my_array(0). 我试图找出my_array(0)中的项目数。 But of course you can't do "my_array(0).count", so trying "my_array.count" simply gives me 1. So how do I get the count of the items in the second dimension?
但是当然您不能执行“ my_array(0).count”,因此尝试“ my_array.count”只会给我1。那么,如何获得第二维中的项数?
Thanks. 谢谢。
您可以使用GetLength
:
Dim dimLength = my_Array.GetLength(1)
如果要查找数组中每个元素的计数,则可能需要考虑使用Sum函数:
Dim totalcount As Integer = m_array.Sum(Function(x) x.Count)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.