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

namespace CS30
{
    class Program
    {
        delegate int DInc(int n);
        delegate bool DIsEqual(double x,double y);
        delegate void DPrint(int n);

        class Klasa
        {
            public int pole1;
            public int pole2;
        };

        static void Main(string[] args)
        {
            //zmienne var
            var i = 5;
            var s = "Helion";
            var d = 1.0;

            Console.Out.WriteLine("Zmienna i: " + i.GetType().ToString());
            Console.Out.WriteLine("Zmienna s: " + s.GetType().ToString());
            Console.Out.WriteLine("Zmienna d: " + d.GetType().ToString());

            //wyrazenia Lambda
            DInc Inc = (int n)=>n+1;
            int incN=Inc(1);
            Console.Out.WriteLine("Inc(1)=" + incN);

            DIsEqual IsEqual = (x,y)=>x==y;
            bool iseq=IsEqual(10,20);
            Console.Out.WriteLine("Czy równe x i y? " + (iseq?"Tak":"Nie"));

            DPrint Print = n => { Console.Out.WriteLine(n.ToString()); };
            Print(10);

            string[] slowa = { "czereśnia", "jabłko", "borówka", "wiśnia", "jagoda" };
            int najkrotsze = slowa.Min(slowo => slowo.Length);
            Console.Out.WriteLine("Najkrotsze slowo ma dlugosc " + najkrotsze + " liter.");

            //inicjacja obiektow
            Klasa k = new Klasa { pole1 = 1, pole2 = 2 };

            //LINQ
            var wybrane = from slowo in slowa where slowo.Length == 6 select new string(slowo.ToCharArray());
            foreach (string slowo in wybrane) Console.Out.WriteLine(slowo);

            var wybrane2 = slowa.Where(slowo => slowo.Length==6).Select(slowo => new string(slowo.ToCharArray()));
            foreach (string slowo in wybrane2) Console.Out.WriteLine(slowo);

        }
    }
}
