luni, 25 august 2014

Single LINQ C# Example

Single

Returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists. 

Example

            string[] cars = { "audi""ford""mercedes""dacia" };
            try
            {
                string car = cars.Single(c => c == "ford");
            }
            catch (System.InvalidOperationException)
            {
                MessageBox.Show ("Car not found!");
            }

Niciun comentariu:

Trimiteți un comentariu