Is IEnumerator or IEnumerable Empty - CSharp System.Collections

CSharp examples for System.Collections:IEnumerable

Description

Is IEnumerator or IEnumerable Empty

Demo Code


using System.Globalization;
using System.Collections.Generic;
using System.Collections;
using System;//w  ww .  j a  v a 2 s .  c  o  m

public class Main{
        /// <summary>
      /// 
      /// </summary>
      /// <param name="enumerator"></param>
      /// <returns></returns>
      public static bool IsEmpty (IEnumerator enumerator)
      {
         if (enumerator != null) {
            enumerator.Reset ();
            return !enumerator.MoveNext ();
         }
         return true;
      }
        /// <summary>
      /// 
      /// </summary>
      /// <param name="enumerable"></param>
      /// <returns></returns>
      public static bool IsEmpty (IEnumerable enumerable)
      {
         if (enumerable != null)
            return IsEmpty (enumerable.GetEnumerator ());
         return true;
      }
        /// <summary>
      /// 
      /// </summary>
      /// <typeparam name="U"></typeparam>
      /// <param name="enumerator"></param>
      /// <returns></returns>
      public static bool IsEmpty<U> (IEnumerator<U> enumerator)
      {
         if (enumerator != null) {
            enumerator.Reset ();
            return !enumerator.MoveNext ();
         }
         return true;
      }
        /// <summary>
      /// 
      /// </summary>
      /// <typeparam name="U"></typeparam>
      /// <param name="enumerable"></param>
      /// <returns></returns>
      public static bool IsEmpty<U> (IEnumerable<U> enumerable)
      {
         if (enumerable != null)
            return IsEmpty (enumerable.GetEnumerator ());
         return true;
      }
}

Related Tutorials