Advertisement
damesova

Untitled

Nov 10th, 2022
1,023
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. public class MonthsOfTheYear : IEnumerable
  2.     {
  3.         private string[] months =
  4.         {
  5.             "January",
  6.             "February",
  7.             "March",
  8.             "April",
  9.             "May",
  10.             "June",
  11.             "July",
  12.             "August",
  13.             "September",
  14.             "October",
  15.             "November",
  16.             "December"
  17.         };
  18.  
  19.         public IEnumerator GetEnumerator()
  20.         {
  21.             for (int index = 0; index < months.Length; index++)
  22.             {
  23.                 // Yield връща всеки месец от годината.
  24.                 yield return months[index];
  25.             }
  26.         }
  27.     }
  28.  
  29. //=================================================================
  30.  
  31. public class Program
  32.     {
  33.         static void Main(string[] args)
  34.         {
  35.             MonthsOfTheYear months = new MonthsOfTheYear();
  36.  
  37.             foreach (var month in months)
  38.             {
  39.                 Console.WriteLine(month);
  40.             }
  41.         }
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement