vb.net 里面如何判断某个值存在一个数组中?

vb.net 里面如何判断某个值存在一个数组中?

第1个回答  2009-09-18
如果是简单类型,可以用数组的indexof方法

Dim colXX As String() = New String() {"1", "2", "3", "4Dim colXX As String() = New String() {"1", "2", "3", "4"}

if (colXX.indexof("2") >= 0) then

return true

end if
第2个回答  推荐于2016-06-02
Public Class Form1

Dim array() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9}

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text <> "" Then
Dim i As Integer
Dim finded As Boolean = False
For i = 0 To array.Length - 1
If array(i).ToString = Trim(TextBox1.Text) Then
Label1.Text = "找到了!位置是:" & i
finded = True
End If
Next
If finded = False Then Label1.Text = "没找到!"
End If
End Sub
End Class本回答被提问者采纳
相似回答