VB.NET Array method not working

In VB.NET, I am trying to define a given string in a String Array. According to my research, Array has a “Contains” method that I can use, so the code looks something like this:

Dim fileTypesZ As String() = {"PDF", "TXT", "DOC", "DOCX", "XLS", "XLSX", "JPG", "JPGE", "BMP", "GIF"}

If (fileTypesZ.Contains(tempTest)) Then

End If

However, VB.NET says that “Contains” is not a member of “System.Array”. Is there any other way that I can use?

+4
source share
2 answers

In Arraythere Contains, but there is Enumerable.Contains, which is the extension method that works on arrays.

Be sure to include Imports System.Linqat the beginning of the file and specify the link System.Core.dllin the links to the project.

+11
source

? 4 Full :

Sub Main()
    Dim fileTypesZ As String() = {"PDF", "TXT", "DOC", "DOCX", "XLS", "XLSX", "JPG", "JPGE", "BMP", "GIF"}

    If (fileTypesZ.Contains("PDF")) Then
        MsgBox("Yay")
    End If
End Sub

, array.contains , "PDF", "PD" - . indexof, .

:   Dim fileTypesZ As String() = { "PDF", "TXT", "DOC", "DOCX", "XLS", "XLSX", "JPG", "JPGE", "BMP", "GIF" }

    If (fileTypesZ.Contains("PD")) Then
        MsgBox("Yay")
    Else
        For i = 0 To fileTypesZ.Length - 1
            If fileTypesZ(i).IndexOf("PD") = 0 Then
                MsgBox("Yay")
            End If
        Next
    End If
+2

All Articles