Summary

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 fluent syntax and the query expression syntax. The former takes a lambda expression for the parameter to represent the logic that will be performed in the sequence enumeration. The latter is a shorthand syntax that we can use in order to perform LINQ queries. In the query expression syntax, .NET Framework provides the keywords for each query operator but not all operators. Our code will be more readable and required less coding when we use the query expression syntax. However, both fluent and query syntax will do the same thing. The difference between them is only the syntax. Each keyword in the query expression syntax has its own extension method in the Enumerable class.

By understanding LINQ, we now have had enough knowledge to create functional programming. In the next chapter, we will discuss asynchronous programming in order to enhance code responsiveness in order to build user-friendly application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset