Saturday, January 3, 2009

Array


Determine if a string in an array
string[] x = new string[] {"apple", "banana", "pear"};

if ( ((IList)x).Contains ("apple"))
{

}

To find the index of a given element in an array
int index;
string[] theList = { "lion", "turtle", "ostrich" };
index = Array.IndexOf(theList, "turtle");

No comments: