Search⌘ K

Deferred Execution

Explore deferred execution in LINQ to understand when and how queries run in C#. Learn to create queries that execute only when accessed, and discover methods to force immediate execution for reliable results.

Introduction

There are subtleties regarding the timing of LINQ query execution. There are essentially two ways of executing a LINQ query:

  • Deferred execution: The LINQ query only executes when we try to address an item from a resulting collection.

  • Immediate execution: The LINQ query executes immediately after construction.

Let’s explore these in detail.

Deferred

...