Exemple #1
0
        static void Main(string[] args)
        {
            // EF (...LINQ2Sql)

            List <int> tal = new List <int>()
            {
                1, 7, 8, 17, 6, 4, 6
            };

            var res1 = (from x in tal
                        where x < 10
                        orderby x
                        select x).ToList();

            var res2 = tal.Where(i => i < 10).OrderBy(i => i).ToList();

            var res3 = tal.OrderBy(i => i).GroupBy(i => i);

            var lst = new PersonNuGetPackage.PersonRepositoryRandom().GetPeople(100);
            //foreach (var item in lst)
            //{
            //    Console.WriteLine(item.Name);
            //}

            var res4 = lst.Where(i => i.Height < 170 && i.Gender == PersonNuGetPackage.Gender.Female).OrderBy(i => i.Name).ThenBy(i => i.Height);

            var res5 = lst
                       .OrderBy(i => i.Name)
                       .Where(i => i.Height < 180)
                       .GroupBy(i => i.Gender);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var lst = new PersonNuGetPackage.PersonRepositoryRandom().Get10People();

            foreach (var p in lst)
            {
                Console.WriteLine(p.Name);
            }

            Console.WriteLine();
            var res1  = from p in lst select p;
            var res11 = lst;

            foreach (var p in res11)
            {
                Console.WriteLine(p.Name);
            }

            Console.WriteLine();
            var res2 = from p in lst orderby p.Gender, p.Name select p;
            var res22 = lst.OrderBy(i => i.Gender).ThenBy(i => i.Name);

            foreach (var p in res22)
            {
                Console.WriteLine(p.Name + " " + p.Gender);
            }

            Console.WriteLine();
            var res3 = from p in lst where p.Height > 150 && p.IsHealthy == true orderby p.Gender, p.Name select p;
            var res33 = lst.Where(i => i.Height > 150 && i.IsHealthy)
                        .OrderBy(i => i.Gender)
                        .ThenBy(i => i.Name);

            foreach (var p in res33)
            {
                Console.WriteLine(p.Name + " " + p.Gender);
            }


            Console.WriteLine();
            //var res4 = from p in lst where p.Height > 150 && p.IsHealthy == true orderby p.Gender, p.Name select p;
            var res44 = lst.Where(i => i.Height > 150 && i.IsHealthy)
                        .OrderBy(i => i.Gender)
                        .ThenBy(i => i.Name)
                        .Select(i => new { Navn = i.Name, Højde = i.Height });

            foreach (var p in res44)
            {
                Console.WriteLine(p.Navn);
            }
        }