.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
?
And this will have the best performance ever. :P
In .NET 2.0, you could do the following if you want the index:
index
will be-1
ifmyStrings
does not containtest
.If you merely want to check for existence:
you can use Array.BinarySearch as described below.
I assume you want to check if any elements in your array contains a certain value (test). If so you want to construct a simple loop. In fact I think you should click here.
Thought I would add another to the mix, first available in .NET 3.5, I believe:
I have found an elegant answer at the page here http://www.dotnettoad.com/index.php?/archives/10-Array.Contains.html. What you have to do in .NET 2.0 is to cast to IList and call Contains method.