From the course: .NET Essentials: Working with LINQ

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Deferred execution: When does the query run?

Deferred execution: When does the query run? - .NET Tutorial

From the course: .NET Essentials: Working with LINQ

Deferred execution: When does the query run?

- You are on your journey, to learn more about LINQ. It doesn't take very long, if you start reading documentations about LINQ, before you run across the term, Deferred Execution. So, let's talk about what that means. Look at the comments on the top of this file. The execution of the query, is distinct, from the creation of the query. You do not retrieve any data just by creating the query. Here's what I mean, I have a list of integers, the potential query is stored in this variable queue and that's going to get all the numbers, order them, and then select them. It's not until I actually do something with this, to execute it, that I will run the query. So, one way of doing that is called ToArray. This is a method that iterates through all of these numbers, and adds them to an array of the same type, so, this will create an integer array. Calling ToList, iterates through it, and this will generate a second list,…

Contents