LINQ Enumerable Class Methods

Updated on 09 Apr 2012,
Published on 01 Oct 2010

The System.Linq.Enumerable class provides a set of static methods which enable to query objects that implement IEnumerable<T>.  The methods of LINQ enumerable class allow to implement the standard query operators over the data source that follow the LINQ pattern at the back end. You can easily implement the LINQ based traversal, filter, and projection over the data source sequence using these standard query operator methods. Many methods in this class are defined as extension methods that extend IEnumerable<T> and enable you to call them like an instance method on any object the implements IEnumerable<T>. There are two types of method in Enumerable class, one that return singleton result and the other that return a sequence of result values. The methods, that return a result sequence, do not read the data source elements until the query object is enumerated. This type of execution is called deferred execution. Whereas the methods, that return singleton result value, consume and execute the data source immediately.

List of Linq Enumerable Class Methods

MethodDescription
Aggregate Applies an accumulator function over the source sequence.
All Finds out whether all the elements of a sequence satisfy a condition.
Any Finds out whether a sequence contains any element.
AsEnumerable Returns the input type as IEnumerable<T>.
Average Computes the average of elements of specified sequence.
Cast Converts the elements of an IEnumerable to the specified type.
Concat Concatenates two sequences.
Contains Finds out whether the sequence contains a specified element by using the default equality comparer.
Count Returns the number of elements in a sequence.
DefaultIfEmpty Returns the elements of the specified sequence or the type parameter's default value as a singleton result if the given sequence is empty.
Distinct Returns the distinct elements from the sequence.
ElementAt Returns the element at a specified index in a sequence.
ElementAtOrDefault Returns the element at a specified index in a sequence or returns default value if the specified index is out of range.
Empty Returns an empty IEnumerable<T> sequence having the specified type argument.
Except Returns a set difference of two sequences by using default equality comparer.
First Returns the first element of a sequence.
FirstOrDefault Returns the first element of the sequence or default value if the sequence is empty.
GroupBy Groups the elements of the sequence based on the specified key.
GroupJoin Joins the elements of two sequences using specified equality comparison keys and groups them based on the specified group key.
Intersect Returns a set intersection of two sequences by using default equality comparer.
Join Combines the elements of two sequences based on the specified matching keys using default equality comparer.
Last Returns the last element of a sequence.
LastOrDefault Returns the last element of a sequence or returns the default value if the sequence has no element.
LongCount Returns the total number of elements in a sequence. Its returns Int64 type value.
Max Returns the maximum value in a sequence.
Min Returns the minimum value in a sequence.
OfType Filters the elements of a sequence based on a specified type.
OrderBy Sorts the elements of a sequence in ascending order.
OrderByDescending Sorts the elements of a sequence in descending order.
Range Returns a sequence of integer numbers within a specified range.
Repeat Return a sequence having duplicates elements of a specified value.
Reverse Inverts the order of elements of a sequence.
Select Transforms each element of a sequence into a new form.
SelectMany It projects each elements of a sequence to an IEnumerable<T> collection and flattens the resulting sequence into s single sequence.
SequenceEqual Compares two sequences based on the equality comparer and returns a Boolean result.
Single Returns a single element from the sequence that satisfies the specified condition. It throws an exception if there are multiple elements satisfying the condition.
SingleOrDefault Returns a single element from the sequence that satisfies the specified condition or default value if no element satisfies it. It throws an exception if there are multiple elements satisfying the condition.
Skip Ignores the specified number of elements and returns rest of the elements.
SkipWhile Ignores the elements until the specified condition is true and returns rest of the elements.
Sum Computes the sum of the elements of a sequence.
Take Returns the specified number of elements from the starting index of a sequence.
TakeWhile Returns the elements from a sequence until the specified condition is true.
ThenBy Sorts the elements of a sequence in ascending order. It extends the functionality of IOrderedEnumerable<TElement> sequence returned by OrderBy method.
ThenByDescending Sorts the elements of a sequence in descending order. It extends the functionality of IOrderedEnumerable<TElement> sequence returned by OrderBy or OrderByDescending method.
ToArray Converts an IEnumerable<T> to an array.
ToDictionary Converts an IEnumerable<T> to Dictionary<TKey, TValue> according to specified key.
ToList Converts an IEnumerable<T> to List<T> according to specified key.
ToLookup Converts an IEnumerable<T> to Lookup<TKey, TElement> according to specified key.
Union Merges the set of elements of two similar types of sequences.
Where Filters the elements of a sequence based on the specified predicate.
Zip Merges the elements of two sequences based on the specified predicate.
0 Responses to "LINQ Enumerable Class Methods"
Leave a Comment
* required
* required
* will not be published
* optional
* hint: http://www.example.com
  • Subscribe via Email
  • HIRE EzineASP.Net Developers