Checks whether or not collection is null or empty. Assumes collection can be safely enumerated multiple times. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:ICollection

Description

Checks whether or not collection is null or empty. Assumes collection can be safely enumerated multiple times.

Demo Code


using System.ComponentModel;
using System.Collections.Generic;
using System.Collections;
using System;//from   w w w  .  ja v  a  2s  .c o m

public class Main{
        /// <summary>
        /// Checks whether or not collection is null or empty. Assumes collection can be safely enumerated multiple times.
        /// 
        /// </summary>
        /// <param name="this"/>
        /// <returns/>
        public static bool IsNullOrEmpty(this IEnumerable @this)
        {
            if (@this != null)
                return !@this.GetEnumerator().MoveNext();
            else
                return true;
        }
}

Related Tutorials