gpt4 book ai didi

vb.net - 计算多维数组中的项目

转载 作者:行者123 更新时间:2023-12-04 23:30:57 24 4
gpt4 key购买 nike

如果我有以下数组:

    Dim Array(4, 10) As String
Array(0, 0) = "100"
Array(0, 1) = "200"
Array(1, 0) = "300"
Array(1, 1) = "400"
Array(1, 2) = "500"
Array(1, 3) = "600"

我如何获得以下计数:
0 = 2
1 = 4

最佳答案

听起来您正在尝试计算 non-Nothing 的数量。数组每个维度中的值。以下功能将允许您这样做

Public Function CountNonNothing(ByVal data As String(,), ByVal index As Integer) As Integer
Dim count = 0
For j = 0 To data.GetLength(1) - 1
If data(index, j) IsNot Nothing Then
count += 1
End If
Next
Return count
End Function

它可以像这样被调用
Dim count1 = CountNonNothing(Array, 0)
Dim count2 = CountNonNothing(Array, 1)

关于vb.net - 计算多维数组中的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5196693/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com