本文整理汇总了VB.NET中System.Array.Exists<T>方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Array.Exists<T>方法的具体用法?VB.NET Array.Exists<T>怎么用?VB.NET Array.Exists<T>使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Array的用法示例。
在下文中一共展示了Array.Exists<T>方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Example
Module Example
Public Sub Main()
Dim planets() As String = {"Mercury", "Venus",
"Earth", "Mars", "Jupiter",
"Saturn", "Uranus", "Neptune"}
Console.WriteLine("One or more planets begin with 'M': {0}",
Array.Exists(planets, Function(element)
Return element.StartsWith("M")
End Function))
Console.WriteLine("One or more planets begin with 'T': {0}",
Array.Exists(planets, Function(element)
Return element.StartsWith("T")
End Function))
Console.WriteLine("Is Pluto one of the planets? {0}",
Array.Exists(planets, Function(element)
Return element.Equals("Pluto")
End Function))
End Sub
End Module
输出:
One or more planets begin with 'M': True
One or more planets begin with 'T': False
Is Pluto one of the planets? False
Module Example
Public Sub Main()
Dim names() As String = { "Adam", "Adel", "Bridgette", "Carla",
"Charles", "Daniel", "Elaine", "Frances",
"George", "Gillian", "Henry", "Irving",
"James", "Janae", "Lawrence", "Miguel",
"Nicole", "Oliver", "Paula", "Robert",
"Stephen", "Thomas", "Vanessa",
"Veronica", "Wilberforce" }
Dim charsToFind() As Char = { "A"c, "K"c, "W"c, "Z"c }
For Each charToFind In charsToFind
Console.WriteLine("One or more names begin with '{0}': {1}",
charToFind,
Array.Exists(names, AddressOf (New StringSearcher(charToFind)).StartsWith))
Next
End Sub
End Module
Public Class StringSearcher
Dim firstChar As Char
Public Sub New(firstChar As Char)
Me.firstChar = Char.ToUpper(firstChar)
End Sub
Public Function StartsWith(s As String) As Boolean
If String.IsNullOrEmpty(s) Then Return False
If s.Substring(0, 1).ToUpper = firstChar Then
Return True
Else
Return False
End If
End Function
End Class
[codeVB]
输出:
[codeVB]
One or more names begin with 'A': True
One or more names begin with 'K': False
One or more names begin with 'W': True
One or more names begin with 'Z': False
Module Example
Public Sub Main()
Dim names() As String = { "Adam", "Adel", "Bridgette", "Carla",
"Charles", "Daniel", "Elaine", "Frances",
"George", "Gillian", "Henry", "Irving",
"James", "Janae", "Lawrence", "Miguel",
"Nicole", "Oliver", "Paula", "Robert",
"Stephen", "Thomas", "Vanessa",
"Veronica", "Wilberforce" }
Dim charsToFind() As Char = { "A"c, "K"c, "W"c, "Z"c }
For Each charToFind In charsToFind
Console.WriteLine("One or more names begin with '{0}': {1}",
charToFind,
Array.Exists(names, Function(s)
If String.IsNullOrEmpty(s) Then Return False
If s.Substring(0, 1).ToUpper = charToFind Then
Return True
Else
Return False
End If
End Function ))
Next
End Sub
End Module
输出:
One or more names begin with 'A': True
One or more names begin with 'K': False
One or more names begin with 'W': True
One or more names begin with 'Z': False