这里我有我的简单代码,包含数组列表和 2 个文本框,当我按下按钮时,脚本必须检查是否在数组列表中找到文本形式 Textbox2。你能帮我修一下吗? 谢谢!
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim pins() As String = {"dgge", "wada", "caas", "reaa"}
If TextBox2.Text = pins() Then
TextBox1.Text = "Succes"
End If End Sub
最佳答案
如果你想使用 LINQ,你可以这样做:
If pins.Contains(TextBox2.Text) Then
TextBox1.Text = "Success"
End If
否则,最简单的选择是使用 List
而不是数组:
Dim pins As New List(Of String)(New String() {"dgge", "wada", "caas", "reaa"})
If pins.Contains(TextBox2.Text) Then
TextBox1.Text = "Success"
End If
但是,如果必须使用数组,可以使用Array
类中的IndexOf
方法:
If Array.IndexOf(TextBox2.Text) >=0 Then
TextBox1.Text = "Success"
End If
关于vb.net - 检查 textbox.text 是否存在于数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15032446/