CHAPTER 12 LINQ TO OBJECTS
{
}
...
While System.Array does not directly implement the IEnumerable interface, it indirectly gains the
required functionality of this type (as well as many other LINQ-centric members) via the static
System.Linq.Enumerable class type.
This utility class defines a good number of generic extension methods (such as Aggregate(),
First(), Max(), etc.), which System.Array (and other types) acquire in the background. Thus, if
you apply the dot operator on the currentVideoGames local variable, you will find a good number of
members not found within the formal definition of System.Array (see Figure 12-1).
Figure 12-1. The System.Array type has been extended with members of System.Linq.Enumerable
The Role of Deferred Execution
Another important point regarding LINQ query expressions is that they are not actually evaluated until
you iterate over the sequence. Formally speaking, this is termed deferred execution. The benefit of this
approach is that you are able to apply the same LINQ query multiple times to the same container, and
rest assured you are obtaining the latest and greatest results. Consider the following update to the
QueryOverInts() method:
static void QueryOverInts()
{
int[] numbers = { 10, 20, 30, 40, 1, 2, 3, 8 };
// Get numbers less than ten.
var subset = from i in numbers where i < 10 select i;
// LINQ statement evaluated here!
foreach (var i in subset)
Console.WriteLine("{0} < 10", i);
450