.NET 2
string[] myStrings = GetMyStrings();
string test = "testValue";
How can I verify if myStrings
contains test
?
.NET 2
string[] myStrings = GetMyStrings();
string test = "testValue";
How can I verify if myStrings
contains test
?
Here's a .NET 2.0 compliant approach. Using
Array.Find
will return null if the value isn't found.C# Approach
If you need a case insensitive match use
s.Equals(test, StringComparison.InvariantCultureIgnoreCase)
.EDIT: with VB.NET 2.0 more effort is required since it doesn't support anonymous delegates. Instead you would need to add a
Function
and useAddressOf
to point to it. You would need to set thetestValue
as a member or property since it will not be passed in to the predicate method. In the following example I useArray.Exists
.VB.NET Approach
How about this:
This should work for .Net 2.0 and VB.Net.
Here is almost the exact same question on msdn. Find String in String Array As others have said you really have two options: 1) Use a list for easier checking 2) Loop through your array to find the string
Instead of using a static array, you could use a List: