Return IEnumerable by yield : IEnumerable : Class Interface C# Source Code


Custom Search

C# Source Code » Class Interface » IEnumerable »

 

Return IEnumerable by yield








    
 

using System;
using System.Collections;

public class Starter {
    public static void Main() {
        foreach (string day in ToEndOfMonth()) {
            Console.WriteLine(day);
        }
    }

    public static IEnumerable ToEndOfMonth() {
        DateTime date = DateTime.Now;

        int currMonth = date.Month;
        while (currMonth == date.Month) {
            string temp = currMonth.ToString() + "/" + date.Day.ToString();
            date = date.AddDays(1);
            yield return temp;
        }
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Class Interface
» IEnumerable