vb.net - 索引数超过索引数组 vb 的维数
问题描述
在我调用我的函数的那一行的sub main中,我遇到了一个我不知道如何修复的错误:
索引数超过索引数组的维数
Module Module1
Sub main()
Dim names() As String = {"heimdall", "hella", "loki", "thor", "tyr", "odin"} 'list in order
Dim last As Integer = names.Length - 1
Dim first As Integer = 0
Dim player As String = "thor"
search(names(), last, first, player)
End Sub
Function search(ByVal names() As String, ByVal last As Integer, ByVal first As Integer, ByVal player As String)
Dim midpoint As Integer = (first + last) \ 2
Dim found As Boolean = False
While found = False
If last < first Then
Return -1
End If
If names(midpoint) > player Then
Return search(names, last, first, midpoint)
found = True
Else
Return midpoint
found = True
End If
End While
Return midpoint 'automatically does this when found = true
End Function
End Module
解决方案
names()
将其传递给search
方法时删除末尾的括号。只有在声明数组时才需要这些。
search(names, last, first, player)
推荐阅读
- ios - 如何更改 SceneKit 中的场景?
- find - Clearcase :查找编号为 0 的所有元素版本,无论哪个分支
- sql - 如何将此混合行/列表转换为所需的输出。(Oracle SQL/发行版:Ora12c)
- spring-data-rest - 在 spring-data-rest 应用程序中验证请求参数
- python - hincrby 和 hget 在 Redis (python) 中返回 True 而不是实际值
- regex-lookarounds - 基于 Python 的正则表达式来匹配来自混合数据集的 twitter 用户名
- spring-data-jpa - 如何使用 Spring Data JPA 审计和 Envers 跟踪删除事件?
- javascript - ArrayInput 可以保存键:'值'吗?
- mysql - 在 VIEW 中运行总计
- android - Firestore 忽略对象中的空值