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

IsNullOrEmpty

Check either IList object is null or empty.

Source

/// <summary>
/// Determines whether the given IList object [is null or empty].
/// </summary>
/// <param name="obj">The object.</param>
/// <returns><c>true</c> if the given IList object [is null or empty]; otherwise, <c>false</c>.</returns>
public static bool IsNullOrEmpty(this IList obj)
{
    return obj == null || obj.Count == 0;
}

Example

List<string> countryList = null;
if (countryList.IsNullOrEmpty())
{ 
 
}
else
{ 
 
}
 
var cityList = new List<string> { "NewYork", "London" };
if (cityList.IsNullOrEmpty())
{
 
}
else
{
 
}

Author: Muhammad Shoaib Ijaz

Submitted on: 29 jan 2019

Language: C#

Type: IList

Views: 6036