I want to understand LINQ and did some research on the matter and discovered that IEnumerable
and IQueryable
have LINQ methods. However when I look at the documentation of these types I don't see any LINQ methods.
Are the LINQ methods extension methods that are inserted in IEnumerable/IQueryable
types at runtime and if so why?
Adding the methods on IEnumerable would mean that all types that derive from IEnumerable would have to implement them themselves. Now with extensions methods we can sort of add implementations to interfaces.
An other side effect would be that code written in .NET 2.0 would still compile with 3.0 when Linq was introduced. Otherwise if you had implemented IEnumerable somewhere in your project you would now have to implement all the new methods in the interface as well.
The LINQ methods for Linq To Objects are defined on the Enumerable class.
Moreover, LINQ searches for methods that are declared using a specific syntax and is not interface or class based. You might find the Edulinq series of Jon Skeet interesting.
MSDN link on extension methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With