static void Main(string[] args)
{
string[] planets = { "Mercury", "Venus",
"Earth", "Mars", "Jupiter",
"Saturn", "Uranus", "Neptune" };
Console.WriteLine("One or more planets begin with 'M': {0}",
Array.Exists(planets, element => element.StartsWith("M")));
Console.WriteLine("One or more planets begin with 'T': {0}",
Array.Exists(planets, element => element.StartsWith("T")));
Console.WriteLine("Is Pluto one of the planets? {0}",
Array.Exists(planets, element => element == "Pluto"));
}
Code (VB.NET)
Public Sub Main()
Dim planets() As String = {"Mercury", "Venus",
"Earth", "Mars", "Jupiter",
"Saturn", "Uranus", "Neptune"}
Console.WriteLine("One or more planets begin with 'M': {0}",
Array.Exists(planets, Function(element)
Return element.StartsWith("M")
End Function))
Console.WriteLine("One or more planets begin with 'T': {0}",
Array.Exists(planets, Function(element)
Return element.StartsWith("T")
End Function))
Console.WriteLine("Is Pluto one of the planets? {0}",
Array.Exists(planets, Function(element)
Return element.Equals("Pluto")
End Function))
End Sub