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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.