Overview

Convert methods change the type of objects.

methods

As* methods change the static type of the collection but do not enumerate it.
To* methods enumerate the collection and put the items into a different collection type.

Methods marked with * force query execution:

MethodsDescriptionQuery expression
AsEnumerableReturns the input typed as IEnumerable<T>N/A
AsQueryableConverts an IEnumerable to IQueryableN/A
Cast<T>Casts the elements of a collection to type Tfrom <type> var in words
OfTypeSelects values depending on their ability to be cast to the specified typeN/A
*ToArrayConverts a collection to an arrayN/A
*ToDictionaryPuts elements into a Dictionary<TKey, TValue> based on a key-selector functionN/A
*ToListConverts a collection to a List<T>N/A
*ToLookupPuts elements into a Lookup<TKey, TValue> based on a key-selector functionN/A

Cast<T> example

In this example, cast a type to a subtype:

IEnumerable people = students;

var query = people
    .Cast<Student>()
    .Where(student => student.Year == GradeLevel.ThirdYear);