CSharp - LINQ AsEnumerable

Introduction

The AsEnumerable operator causes its input sequence of type IEnumerable<T> to be returned as type IEnumerable<T>.

Prototypes

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

The AsEnumerable operator casts the input sequence as a normal IEnumerable<T> sequence, allowing a Standard Query Operator method to be called.

Exceptions

There are no exceptions.

using System;
using System.Linq;
using System.Data.Linq;

using nwind;

Northwind db = new Northwind(@"Data Source=.\SQLEXPRESS;Initial Catalog=Northwind");

var custs =
  from c in db.Customers
  where c.City == "Rio de Janeiro"
  select c;

foreach (var cust in custs)
    Console.WriteLine("{0}", cust.CompanyName);

Calling the AsEnumerable Operator Before Calling the Reverse Operator

Northwind db = new Northwind(@"Data Source=.\SQLEXPRESS;Initial Catalog=Northwind");

var custs =
        (from c in db.Customers
         where c.City == "Rio de Janeiro"
   select c)
  .AsEnumerable()
  .Reverse();

foreach (var cust in custs)
  Console.WriteLine("{0}", cust.CompanyName);