【发布时间】:2022-01-01 11:44:58
【问题描述】:
我一直在尝试返回数组中的最大数字,但我一直得到 13。我在这里做错了什么?
Dim maxage As Integer = 0
Dim ageList() As Integer = {12, 13, 18, 11, 5, 3}
Dim i As Integer
For i = 0 To UBound(ageList)
If i > maxage Then
maxage = ageList(i)
End If
Next i
Console.WriteLine(maxage)
Console.ReadLine()
【问题讨论】:
-
你可以试试 if ageList(i) > maxage then
-
看起来这是 [VB.NET] 而不是 [VBA]。在 VB.NET 中,您也可以使用
{12, 13, 18, 11, 5, 3}.Max或ageList.Max。在 VBA 中,您可以使用WorksheetFunction.Max(ageList)。