LINQ has made our task of querying a collection easier because we don't need to learn much syntax to access different types of collections. It implements a deferred execution concept, which means that the query will not be executed in the constructor time but in the enumeration process. Almost all query operators provide the deferred execution concept; however, there are exceptions for the operators that do the following:
Return a scalar value or single element, such as Count
and First
.
Convert the result of query; they are ToList
, ToArray
, ToDictionary
, and ToLookup
. They are also called conversion operators.
In other words, methods that return a sequence implement deferred execution for instance, the Select
method (IEnumerable<X>-> Select -> IEnumerable<Y>)
and methods that return a single object don't implement deferred execution, for instance, the First
method (IEnumerable<X>-> First -> Y)
.
There are two types of LINQ querying syntaxes; they are the...