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

IsNullOrEmpty

Checks if the collection is null or empty

Source

public static bool IsNullOrEmpty(this System.Collections.Generic.IEnumerable<T> source)
{
    return source = null || !source.Any();
}

Example

string[] strArr = null;
int[] intArr = {};
bool[] booArr = {true, false};

bool result1 = strArr.IsNullOrEmpty(); //returns true
bool result2 = intArr.IsNullOrEmpty(); //returns true
bool result3 = booArr.IsNullOrEmpty(); //returns false

Author: Linquize

Submitted on: 5 feb 2011

Language: C#

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

Views: 3364