C# List Exists
Description
List
determines whether the List
Syntax
List.Exists
has the following syntax.
public bool Exists(
Predicate<T> match
)
Parameters
List.Exists
has the following parameters.
match
- The Predicatedelegate that defines the conditions of the elements to search for.
Returns
List.Exists
method returns true if the List contains one or more elements that match the conditions
defined by the specified predicate; otherwise, false.
Example
using System;//from w w w . j a v a 2 s . c om
using System.Collections.Generic;
public class Example
{
public static void Main()
{
List<string> myData = new List<string>();
myData.Add("B");
myData.Add("D");
Console.WriteLine(myData.Exists(MyCondition));
}
private static bool MyCondition(String s)
{
return s.ToLower().EndsWith("a");
}
}
The code above generates the following result.