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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var elemek = new List<Pelda>
            {
                new Pelda {X = 11, Y = 12 },
                new Pelda {X = 51, Y = 98 },
                new Pelda {X = 17, Y = 18 },
                new Pelda {X = 11, Y = 52 },
                new Pelda {X = 14, Y = 18 },
                new Pelda {X = 41, Y = 16 },
                new Pelda {X = 12, Y = 12 }
            };

            var elemek2 = new List<Pelda2>
            {
                new Pelda2 {Z = 11, Y = 12 },
                new Pelda2 {Z = 10, Y = 98 },
                new Pelda2 {Z = 17, Y = 18 },
                new Pelda2 {Z = 11, Y = 55 },
                new Pelda2 {Z = 16, Y = 18 },
                new Pelda2 {Z = 42, Y = 16 },
                new Pelda2 {Z = 12, Y = 13 }
            };

            var eredmeny = (from elem in elemek
                           group elem by elem.Y into csoport
                           select csoport);

            var eredmeny2 = elemek.GroupBy(elem => elem.Y);

            
            Console.WriteLine();

            foreach (var group in eredmeny)
            {
                foreach (var item in group)
                {
                    Console.WriteLine($"{item.X} {item.Y}");
                }
            }

            var eredmeny3 = from elem in elemek
                            join elem2 in elemek2
                            on elem.Y equals elem2.Y
                            select new
                            {
                                X = elem.X,
                                Y = elem.Y,
                                Z = elem2.Z
                            };

            var eredmeny4 = elemek.Join(elemek2, i => i.Y, j => j.Y, (i, j) => new
            {
                X = i.X,
                Y = i.Y,
                Z = j.Z
            });

            foreach (var item in eredmeny3)
            {
                Console.WriteLine($"{item.X},{item.Y},{item.Z}");
            }

            Console.WriteLine();

            foreach (var item in eredmeny4)
            {
                Console.WriteLine($"{item.X},{item.Y},{item.Z}");
            }
            Console.WriteLine();

            var eredmeny5 = eredmeny4.Skip(1).Take(2);

            foreach (var item in eredmeny5  )
            {
                Console.WriteLine(item);
            }

        }

        struct Pelda2{
            public int Y { get; set; }
            public int Z { get; set; }
        }

        struct Pelda
        {
            public int X { get; set; }
            public int Y { get; set; }
        }
    }
}
