Recall & Review
beginner
What are immediate execution methods in C# LINQ?
Immediate execution methods run the query right away and return a result immediately, unlike deferred execution which waits until the data is needed.
Click to reveal answer
beginner
Name three common immediate execution methods in C# LINQ.
Common immediate execution methods include
ToList(), ToArray(), and Count().Click to reveal answer
intermediate
What is the difference between
ToList() and Count() in terms of immediate execution?ToList() creates a new list with all elements immediately, while Count() immediately calculates how many elements are in the sequence.Click to reveal answer
intermediate
Why might you use an immediate execution method instead of deferred execution?
You use immediate execution when you want to get the results right away, for example to avoid multiple enumerations or to capture the current state of data.
Click to reveal answer
advanced
What happens if you call
ToList() on a LINQ query multiple times?Each call to
ToList() executes the query again and creates a new list, which can be inefficient if the source data changes or is expensive to query.Click to reveal answer
Which of the following is an immediate execution method in C# LINQ?
✗ Incorrect
ToList() immediately executes the query and returns a list. The others use deferred execution.What does the
Count() method do in LINQ?✗ Incorrect
Count() immediately counts and returns the number of elements in the sequence.Calling
ToArray() on a LINQ query will:✗ Incorrect
ToArray() forces immediate execution and returns an array of the results.Which method does NOT cause immediate execution?
✗ Incorrect
Select() uses deferred execution and does not run the query immediately.Why is immediate execution useful?
✗ Incorrect
Immediate execution runs the query and returns results immediately, which can improve performance and consistency.
Explain what immediate execution methods are in LINQ and give examples.
Think about when the query runs and returns results.
You got /3 concepts.
Describe a situation where using an immediate execution method is better than deferred execution.
Consider when you want to fix the data results right away.
You got /3 concepts.