LINQ and Laziness

Learn about LINQ and deferred 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 movie is a favorite movie or not. Then, let’s print a different message once we have found a favorite movie. Keep an eye on the order of the printed messages.

Get hands-on with 1200+ tech skills courses.