That??™s the difference
between using List.ConvertAll and Enumerable.Select: the former creates a
whole new in-memory list, whereas the latter just iterates through the original
sequence, yielding a single converted element at a time.
This is a best-case scenario, however. There are times where in order to fetch the
first result of a query, you have to evaluate all of the data from the source. We??™ve
already seen one example of this in the previous chapter: the Enumerable.Reverse
method needs to fetch all the data available in order to return the last original element
as the first element of the resulting sequence. This makes Reverse a buffering
operation??”which can have a huge effect on the efficiency (or even feasibility) of your
overall operation. If you can??™t afford to have all the data in memory at one time, you
can??™t use buffering operations.
Just as the streaming aspect depends on which operation you perform, some transformations
take place as soon as you call them, rather than using deferred execution.
This is called immediate execution. Generally speaking, operations that return another
sequence (usually an IEnumerable
or IQueryable) use deferred execution,
whereas operations that return a single value use immediate execution.
The operations that are widely available in LINQ are known as the standard query
operators??”let??™s take a brief look at them now.
Pages:
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533