LINQ queries actually run - LINQ

Q.   When do LINQ queries actually run?
- Published on 31 Aug 15

a. When they are iterated over in a foreachloop
b. When calling the ToArray() method on the range variable
c. When calling the ToList() method on the range variable
d. All of the above

ANSWER: All of the above
 
In the above question all options are correct. By default LINQ uses deferred query execution. It means that LINQ queries are always executed when you iterated the query variable, not when the query variable is created. LINQ queries actually run when they are iterated over in a foreach loop.

Post your comment / Share knowledge


Enter the code shown above:
 
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)