vb.net 里面如何判断某个值存在一个数组中?
答案:2 悬赏:70 手机版
解决时间 2021-11-21 20:49
- 提问者网友:我的未来我做主
- 2021-11-21 09:19
vb.net 里面如何判断某个值存在一个数组中?
最佳答案
- 五星知识达人网友:深街酒徒
- 2021-11-21 09:43
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
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
全部回答
- 1楼网友:第幾種人
- 2021-11-21 11:20
如果是简单类型,可以用数组的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
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
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯