コード例 #1
0
ファイル: Test.cs プロジェクト: antonpopov/TelerikAcademy
        static void Main()
        {
            Student[] listOfStudents = new Student[]
            {
                new Student("Petar", "Petrov", 21),
                new Student("Stamat", "Doichinov", 22),
                new Student("Gosho", "Todorov", 17),
                new Student("Ivan", "Zahariev", 30),
                new Student("Zahari", "Ivanov", 12),
                new Student("Albena", "Albenova", 23),
                new Student("Albena", "Ivanova", 31),
                new Student("Ivan", "Albenov", 18)
            };

            var resultLambda = listOfStudents
                .OrderByDescending(st => st.FirstName)
                .ThenByDescending(st => st.LastName);

            var resultLINQ =
                from st in listOfStudents
                orderby st.FirstName descending,
                st.LastName descending
                select st;

            Console.WriteLine("Lambda: ");
            Student.Information(resultLambda);
            Console.WriteLine("LINQ");
            Student.Information(resultLINQ);
        }
コード例 #2
0
        static void Main()
        {
            Student[] array = new Student[] { new Student("Asen", "Borisov", 19),
                                              new Student("Boris", "Asenov", 25),
                                              new Student("Gosho", "Peshov", 20),
                                              new Student("Pesho", "Goshov", 88),
                                              new Student("Pesho", "Peshov", 40) };

            Console.WriteLine("Task 3: First before last");
            FirstBeforeLast(array);
            Console.WriteLine(separator);

            Console.WriteLine("Task 4: Age Range");
            AgeRange(array);
            Console.WriteLine(separator);

            Console.WriteLine("Task 5: Order students");
            Console.WriteLine("With lambda: ");
            var sortedArray = array.OrderByDescending(st => st.FirstName)
                              .ThenByDescending(st => st.LastName);

            Console.WriteLine(string.Join(Environment.NewLine, sortedArray));
            Console.WriteLine("With LINQ: ");
            OrderStudents(array);
        }