ExtensionMethod.NET Home of 875 C#, Visual Basic, F# and Javascript extension methods

IsNullOrEmpty

Check whether a collection is null or doesn't contain any elements.

Source

public static bool IsNullOrEmpty<T>(this IEnumerable<T> collection)
{
    return collection == null || collection.Count() == 0;
}

Example

var list = new List<Customer>();
var isEmpty = list.IsNullOrEmpty();

Author: Dimaz Pramudya

Submitted on: 20 dec 2009

Language: C#

Type: System.Collection.Generic.IEnumerable<T>

Views: 5621