extends IEnumerable : IEnumerable « Class « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;


public class MainClass{

   public static void Main(string[] args){   
         List<String>   TestData = new List<String>();
         var ThisQuery = from TheData in TestData select TheData;
         
         foreach (var ThisElement in ThisQuery.DefaultIfEmpty())
            Console.WriteLine(ThisElement);

         TestData.Add("One");
         TestData.Add("Two");
         TestData.Add("Three");

         foreach (var ThisElement in ThisQuery.DefaultIfEmpty())
            Console.WriteLine(ThisElement);

   }
}
      public static class MyStrings
      {
         public static IEnumerable<string> DefaultIfEmpty(this IEnumerable<string> source)
         {
            if (source.Count<String>() > 0)
               return source;
            else
            {
               List<string> DefaultValue = new List<string>();
               DefaultValue.Add("Empty");
               return DefaultValue;
            }
         }
      }








7.57.IEnumerable
7.57.1.IEnumerable<T>
7.57.2.Supporting foreach with IEnumerable and IEnumerator
7.57.3.extends IEnumerable