如何判断数组中是否有某元素
本帖最后由 bcrun 于 2013-08-04 11:36:04 编辑
Sub A()
Dim vArrayA = New String("A", "B", "C")
Dim vMatch As Predicate(Of String)
Dim B As Boolean
B = Array.Exists(vArrayA, vMatch)
End Sub
Sub A()
'Dim vArrayA = New String("A", "B", "C")
Dim vArrayA() as String= {"A", "B", "C"}
Dim vMatch As Predicate(Of String)
Dim B As Boolean
vMatch= AddressOf StringMatch
B = Array.Exists(vArrayA, vMatch)
listBox1.Items.Add( B.ToString())
End Sub
Sub TestExist()
Dim dinosaurs() As String = {"Compsognathus", _
"Amargasaurus", "Oviraptor", "Velociraptor", _
"Deinonychus", "Dilophosaurus", "Gallimimus", _
"Triceratops"}
Dim B As Boolean
B = CType(dinosaurs, IList).Contains("Gallimimus")
listBox1.Items.Add( B.ToString())
End Sub
Sub MainFormLoad(sender As Object, e As EventArgs)
A
TestExist
End Sub
Private Function StringMatch(s As String) As Boolean
' return s == II[i].ToString()
Return s = "B"
End Function