using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FlowControl
{
    class Examples60_61
    {
        public static void ForeachArray()
        {
            // Listing 2-60
            string[] messages = GetMessagesFromSomewhere();
            foreach (string message in messages)
            {
                Console.WriteLine(message);
            }
        }

        private static string[] GetMessagesFromSomewhere()
        {
            return Enumerable.Range(1, 5).Select(i => "Wiadomość " + i).ToArray();
        }


        // Listing 2-61
        public static void ShowMessages(IEnumerable<string> messages)
        {
            foreach (string message in messages)
            {
                Console.WriteLine(message);
            }
        }

        public static void CallShowMessages()
        {
            ShowMessages(Enumerable.Range(1, 5).Select(i => "Wiadomość " + i));
        }
    }
}
