Arrays ..

  • Thread starter Thread starter Jacek Jurkowski
  • Start date Start date
J

Jacek Jurkowski

String[] s = new String[]{"a","b","c","d"};

What is the simpliest way to check if s
contains value "c"?
 
Jacek said:
String[] s = new String[]{"a","b","c","d"};

What is the simpliest way to check if s
contains value "c"?

Array.IndexOf(s, "c") != -1

HTH,
Stefan
 
Use System.Array.IndexOf(or System.Array.BinarySearch, depending on the
context).

Example:
public static bool ArrayContains ( string [] array, string value )
{
return System.Array.IndexOf(array, value) > -1;
}
 
Back
Top