我不知道这些代码有什么问题?
持续生产:
IndexOutOfRangeException
Module Module1
Sub Main()
Console.WriteLine("Please input the length of the array")
Dim n As Integer = Console.ReadLine()
Dim numbers(n - 1) As Integer
Console.WriteLine("Please inform us the number you want to find")
Dim x As Integer = Console.ReadLine()
For i = 0 To n - 1
Console.WriteLine("Please input the {0} number", i)
numbers(i) = Console.ReadLine()
Next
examining(x, n, numbers(n - 1))
Console.ReadLine()
End Sub
Sub examining(ByVal x As Integer, ByVal n As Integer, ByVal ParamArray numbers() As Integer)
Dim i As Integer
For i = 0 To n - 1
If numbers(i) = x Then
Console.WriteLine("There exists {0} in the array", x)
Exit For
End If
Next
If i = n - 1 Then Console.WriteLine("{0} does not exist in the array", x)
End Sub
End Module
检查数组是否包含内容的简单方法:
If numbers.Contains(x) Then
'it does
Else
'it does not
End If