39.
string[] colors = { "green", "brown", "blue", "red" };
What does this expression evaluate to?
colors.OrderBy(c => c.Length).First()
View Description
This throws an InvalidOperationException: the sequence emitted by OrderBy contains four elements, and Single demands exactly one element. To get the result "red", you must use the First operator instead:
colors.OrderBy(c => c.Length).First()
Another option is to use FirstOrDefault (unlike First, FirstOrDefault doesn't throw an exception there are zero elements in the sequence).
Single is good for retrieving a row from a table by primary key, in a LINQ to SQL query:
Customer c = dataContext.Customers.Single (c => c.ID == 123);
In this case, you'd want an exception to be thrown if there were two customers with that ID.