Determines whether an array contains elements : Array Search « Data Structure « VB.Net






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

1.Array: Binary Search, CopyArray: Binary Search, Copy
2.Array.Find<(Of <(T>)>),
3.Array.FindLast<(Of <(T>)>)
4.Array.FindAll<(Of <(T>)>)
5.Array.Exists<(Of <(T>)>)
6.Array.TrueForAll<(Of <(T>)>)
7.All three generic overloads of the Array.IndexOf method.
8.Searches an entire one-dimensional sorted Array for a specific element
9.Searches sorted Array for a specific element, using the IComparable(Of T) generic interface
10.Searches sorted Array for a value using the specified IComparer(Of T) generic interface.
11.Searches for an element that matches the conditions defined by the specified predicate
12.Searches for an element that matches the conditions
13.Searches for the object and returns the index of the first occurrence
14.Searches for the first occurrence of the duplicated value in the last section of the Array
15.Searches for the first occurrence of the duplicated value in a section of the Array
16.Array.IndexOf(T) searches for the object and returns the index of the first occurrence
17.Searches for the object and returns the index of the last occurrence
18.Searches for the last occurrence of the duplicated value in the first section of the Array.
19.Searches for the last occurrence of the duplicated value in a section of the Array.
20.Array.LastIndexOf(T) searches for the specified object and returns the index of the last occurrence
21.Array.FindLastIndex