Determines whether an array contains elements
Imports System
Public Class Main
Public Shared Sub Main()
Dim numbers() As String = { "Five","Two","Ten","Twenty","Thirty","Zero","Four","Last" }
For Each num As String In numbers
Console.WriteLine(num)
Next num
Dim dinoType As Predicate(Of String)
dinoType = AddressOf EndsWithRaptor
Console.WriteLine(Array.Exists(numbers, dinoType))
Dim subArray() As String = Array.FindAll(numbers, dinoType)
For Each num As String In subArray
Console.WriteLine(num)
Next num
End Sub
Private Shared Function EndsWithRaptor(s As String) As Boolean
If (s.Length > 3) AndAlso (s.Substring(s.Length - 4).ToLower() = "t") Then
Return True
Else
Return False
End If
End Function
End Class
Related examples in the same category