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

Remote Versus Local with AsEnumerable

One final operator we need to take a look at is AsEnumerable. At first, it looks quite useless:

static IEnumerable<T> AsEnumerable<T>(this IEnumerable<T> source);

Looking at the implementation of the operator, this observation gets confirmed even more because it doesn’t do anything but return the source parameter object. So, what’s its purpose? The answer is to be found in C#’s method resolution rules in the context of extension methods.

It’s clear that the AsEnumerable method will be available on every object that implements the IEnumerable<T> interface (assuming the System.Linq namespace is imported, that is). One more specialized interface that’s based on IEnumerable<T> is the IQueryable<T> interface, ...

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