Wednesday, August 25, 2010

Array.Find(), Array.FindLast() and Array.FindAll()

static void Main(string[] args)
{
string[] arr = new string[5] { "tests", "Google", "good","yes","grey" };

Console.WriteLine(Array.Find(arr, StartwithG));
Console.WriteLine(Array.FindLast(arr, StartwithG));

string[] arrstartwithg = Array.FindAll(arr, StartwithG);
foreach (string str in arrstartwithg)
{
Console.WriteLine(str);
}

}

static bool StartwithG(string str)
{
if (str.ToLower().StartsWith("g"))
return true;
else return false;
}

No comments: