string array.Contains?

前端 未结 10 1438
无人及你
无人及你 2021-02-07 03:22

.NET 2

string[] myStrings = GetMyStrings();    
string test = \"testValue\";

How can I verify if myStrings contains test

10条回答
  •  不知归路
    2021-02-07 03:51

    How about this:

    Sub Main
        Dim myStrings(4) As String
        myStrings(0) = "String 1"
        myStrings(1) = "String 2"
        myStrings(2) = "testValue"
        myStrings(3) = "String 3"
        myStrings(4) = "String 4"
    
        Dim test As String = "testValue"
    
        Dim isFound As Boolean = Array.IndexOf(myStrings, test) >= 0
    
        If isFound Then
            Console.WriteLine("Found it!")
        End If
    End Sub
    

    This should work for .Net 2.0 and VB.Net.

提交回复
热议问题