using System;
public class City
{
public static void Main()
{
// Create an array of string objects.
string[] names = new string[3];
names[0] = "London";
names[1] = "Paris";
names[2] = "Zurich";
// To find the first city name structure which starts with alphabet "P", pass the array
// and a delegate that represents the ProcessCity method to the Shared
// Find method of the Array class.
string[] city;
city = Array.Find(names, StartsWithP);
// Note that you do not need to create the delegate
// explicitly, or to specify the type parameter of the
// generic method, because the C# compiler has enough
// context to determine that information for you.
// Display the first city found.
Console.WriteLine("City Match Found: {0}", city);
}
// This method implements the test condition for the Find
// method.
public static bool StartsWithP(string item)
{
return item.StartsWith("P", StringComparison.InvariantCultureIgnoreCase);
}
}
/* This code example produces the following output:
City Match Found: Paris
*/