Module Module1
Sub Main()
'Find1()
Find2()
Console.Read()
End Sub
Private Sub Find1()
Dim data() As Integer = {1, 3, 5, 6, 9, 11, 13, 15, 17, 19}
Dim i, index As Integer
'index = -1
For i = 0 To data.GetUpperBound(0)
If data(i) = 11 Then
index = i
Exit For
End If
Next
Console.WriteLine("11这个数在数组的第" & index + 1 & "位")
End Sub
Private Sub Find2()
Dim data() As Integer = {1, 3, 5, 6, 9, 11, 13, 15, 17, 19}
Console.WriteLine("输入要搜索的数据")
Dim intNum As Integer = Console.ReadLine
Dim blnFind As Boolean = False
Dim index As Integer
For Each ele In data
If ele = intNum Then
index = Array.IndexOf(data, ele)
blnFind = True
Exit For
End If
Next
If blnFind Then
Console.WriteLine(intNum & "这个数在数组的第" & index + 1 & "位")
Else
Console.WriteLine("未找到数据")
End If
End Sub
End Module