Overloading Query Expression Syntax

All of this means that you can overload the query expression syntax by implementing the right (sub)set of methods. For instance, if you have some type that’s filterable (maybe in a more efficient manner than regular IEnumerable<T> objects), all it takes to enable the use of the where keyword is to implement a well-suited Where method. Whether that method is an instance method directly on the object being filtered or an extension method defined elsewhere doesn’t matter.

This has pretty far-reaching implications, allowing quite different signatures for query operator implementations. For example, the following example shows a method that will get all the matches for a regular expression, given an input string, ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.