Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MonthsOfTheYear : IEnumerable
- {
- private string[] months =
- {
- "January",
- "February",
- "March",
- "April",
- "May",
- "June",
- "July",
- "August",
- "September",
- "October",
- "November",
- "December"
- };
- public IEnumerator GetEnumerator()
- {
- for (int index = 0; index < months.Length; index++)
- {
- // Yield връща всеки месец от годината.
- yield return months[index];
- }
- }
- }
- //=================================================================
- public class Program
- {
- static void Main(string[] args)
- {
- MonthsOfTheYear months = new MonthsOfTheYear();
- foreach (var month in months)
- {
- Console.WriteLine(month);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement