Don??™t
panic, though??”just follow the steps shown in chapter 3, assigning different types to
different type parameters until you??™ve got a concrete example of what the method
would look like. That usually makes it a lot easier to understand what??™s going on.
We??™ll use the example of defect tracking as our sample data when we look at query
expressions in the next chapter.
These examples aren??™t particularly involved ones, but I hope you can see the
power of chaining method calls together, where each method takes an original collection
and returns another one in some form or other, whether by filtering out some
values, ordering them, transforming each element, aggregating some values, or many
other options. In many cases, the resulting code can be read aloud and understood
immediately??”and in other situations it??™s still usually a lot simpler than the equivalent
code would have been in previous versions of C#.
Now that we??™ve seen some of the extension methods provided for us, we??™ll consider
just how and when it makes sense for you to write them yourself.
10.4 Usage ideas and guidelines
Like implicit typing of local variables, extension methods are controversial. It would
be hard to claim that they make the overall aim of the code harder to understand in
many cases, but at the same time they do obscure the details of what method is getting
called.
Pages:
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513