LINQ in practice
Now, we can build a console app to explore practical examples of using LINQ.
Understanding deferred execution
LINQ uses deferred execution. It is important to understand that calling most of the above extension methods does not execute a query and get the results. Most of these extension methods return a LINQ expression that represents a question, not an answer. Let's explore:
- Use your preferred code editor to create a new project, as defined in the following list:
- Project template: Console App /
console
- Project file and folder:
LinqWithObjects
- Solution file and folder:
Chapter11
- Project template: Console App /
- In the project file, globally and statically import the
System.Console
class. - Add a new class file named
Program.Helpers.cs
. - In
Program.Helpers.cs
, delete any existing statements, and then define a partialProgram
class with a method to output a section title, as shown in the following code:
partial class Program
{
private static void SectionTitle(string title)
{
ConsoleColor...