Search⌘ K
AI Features

LINQ and Laziness

Explore the concept of LINQ deferred execution through experiments with the Where method in C#. Understand how LINQ delays query evaluation until results are iterated, and how methods like ToList force immediate query execution.

We’ve learned about the LINQ Where method and how LINQ doesn’t change input collections. Before we dive into other LINQ methods, let’s get to know deferred execution, another LINQ feature.

What’s deferred execution?

To learn about LINQ and deferred execution, let’s run some experiments.

First, let’s modify our previous example to print a message inside the IsFavorite() method before checking if a ...