O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required