How to use Array.FindIndex<T> method to search and returns the index of the first occurrence of an element in VB.NET

1 Answer

0 votes
Module Module1

    Sub Main()
        Dim s() As String = {"PHP", "C", "C++", "C#", "Java", "JavaScript",
                             "VB.NET", "VB6", "Pascal", "Python"}

        Console.WriteLine("Array.FindIndex(s, AddressOf StartWithC): {0}",
                           Array.FindIndex(s, AddressOf StartWithC))
    End Sub

    Private Function StartWithC(ByVal s As String) As Boolean

        If (s.Substring(0, 1).ToLower() = "c") Then
            Return True
        Else
            Return False
        End If
    End Function

End Module

' run:
' 
' Array.FindIndex(s, AddressOf StartWithC): 1

 



answered Apr 16, 2016 by avibootz
...