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

是这样的,想请分析下,vb.net 里面如何判断某个值存在一个数组中?
最新回答
蘇瑾熙

2024-11-07 01:48:13

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

2024-11-07 02:47:17

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