sooprise
sooprise

Reputation: 23177

Linq Query ToList() Acting Up

var v = object.where(a => a.date > DateTime(2000,1,1,));
list = v.ToList();

Ok, so for the following code, i have break points set up on each line. When i get to the first line, I run the code (F5) until it reaches the 2nd line. When i step forward (F11) from the second line, it returns to the first line. When I run the code (F5) it doesn't make it to the second line and throws an error.

Is my linq query wrong, or is something else not working? I'm totally confuzored.

Upvotes: 2

Views: 420

Answers (1)

SLaks
SLaks

Reputation: 887225

Due to deferred execution, the lambda expression in the first line will only execute when the result is iterated in the second line.

This behavior is completely correct.

Here is a very good explanation.

Upvotes: 3

Related Questions