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

来源:百度知道 编辑:UC知道 时间:2024/06/17 16:55:09
vb.net 里面如何判断某个值存在一个数组中?

如果是简单类型,可以用数组的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

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.Te