This project has moved and is read-only. For the latest updates, please go here.

System.Collections.Generic.IEnumerable extension methods

Contains(Func<T, bool> predicate)

Summary: Returns a boolean indicating whether the IEnumerable contains any matches to the predicate.
C# Example:
var arr = new string[0];
var b = arr.Contains(d => d == "Chris");
if (b) {
    // do something
}

Each(Action<T> action)

Summary: Performs the specified action on each element in the IEnumerable.
C# Example:
var combinedLength = 0;

var arr = new string[] {
    "Chris", "Steve", "John"
};

arr.Each(d => combinedLength += d.Length);
// combinedLength now equals 14

IsEmpty()

Summary: Returns a boolean indicating whether the IEnumerable is Empty.
C# Example:
var arr = new string[0];

if (arr.IsEmpty()) {
    // do something
}

IsNullOrEmpty()

Summary: Returns a boolean indicating whether the IEnumerable is Null or Empty.
C# Example:
string[] arr = null;

if (arr.IsNullOrEmpty()) {
    // do something
}

ToPaginatedList(int pageIndex, int pageSize)

Summary: Returns an PaginatedList<> based on the specified IEnumerable<> and page index and page size. The total count is gathered from the IEnumerable itself.
C# Example:
var paginatedList = arr.ToPaginatedList(0, 25);

ToPaginatedList(int pageIndex, int pageSize, int totalCount)

Summary: Returns a PaginatedList<> based on the specified IEnumerable with the specified page index, page size and total count set. This is for using when the IEnumerable contains a known subset of the full data set.
C# Example:
var paginatedList = arr.ToPaginatedList(0, 25, 124);

Last edited May 4, 2012 at 3:11 PM by crpietschmann, version 7

Comments

No comments yet.