By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,458 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,458 IT Pros & Developers. It's quick & easy.

Arrays ..

P: n/a
String[] s = new String[]{"a","b","c","d"};

What is the simpliest way to check if s
contains value "c"?
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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;
}
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Jacek Jurkowski" <jj********@datacomp.szczecin.pl> wrote in message
news:eS**************@TK2MSFTNGP10.phx.gbl...
String[] s = new String[]{"a","b","c","d"};

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

Nov 16 '05 #2

P: n/a
Jacek Jurkowski wrote:
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
Nov 16 '05 #3

P: n/a
Thanks :-)
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.