luni, 25 august 2014

LINQ FirstOrDefault C# Example

FirstOrDefault 

Returns the first element of the sequence that satisfies a condition or a default value if no such element is found. 

Example

string[] cars = { "audi""ford""mercedes""dacia" };
string car = cars.FirstOrDefault(c => c == "ford"); //ford
car = cars.FirstOrDefault(c => c == "ford1"); //null

Niciun comentariu:

Trimiteți un comentariu