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

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.