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


Checks if the collection is null or empty


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


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: 4042