static void Main()
        {
            Student[] students = new Student[5];

            students[0] = new Student("Emo", "Georgiev");
            students[1] = new Student("Georgi", "Dulgerov");
            students[2] = new Student("Doncho", "Stoqnov");
            students[3] = new Student("Doncho", "Ivanov");
            students[4] = new Student("Doncho", "Mladenov");

            var sotedStudents = students.OrderBy(stud => stud.FirstName).ThenBy(s => s.LastName);

            Console.WriteLine("Sort whit extension methods OrderBy() and ThenBy()");
            foreach (var stud in sotedStudents)
            {
                Console.WriteLine("{0} {1}", stud.FirstName, stud.LastName);
            }

            Console.WriteLine("\nSort whit LINQ");

            var sortedWhitLinq = from s in students
                                 orderby s.FirstName, s.LastName
                                 select s;

            foreach (var stud in sortedWhitLinq)
            {
                Console.WriteLine("{0} {1}", stud.FirstName, stud.LastName);
            }
        }
Ejemplo n.º 2
0
 private static void OrderWithLambda(Student[] students)
 {
     students = students.OrderByDescending(t => t.FirstName).ThenByDescending(t => t.LastName).ToArray();
     foreach (var student in students)
     {
         Console.WriteLine(student.ToString());
     }
 }
Ejemplo n.º 3
0
        private static void OrderWithLINQ(Student[] students)
        {
            var studentsSort = from student in students
                           orderby student.FirstName descending, student.LastName descending
                           select student;

            foreach (var student in studentsSort)
            {
                Console.WriteLine(student.ToString());
            }
        }
Ejemplo n.º 4
0
        static void Main()
        {
            Student[] students = new Student[] { new Student(firstName: "Pesho", lastName:"Ivanov"),
                                                new Student("Assen", "Georgiev"),
                                                new Student("Ivanka",  "Tsoneva"),
                                                new Student( "Gogo", "Asenov"),
                                                new Student("Niki","Kostov"),
                                                new Student( "Ivanka",  "Asenova")};

            //Using Lambda Expressions
            OrderWithLambda(students);

            //Using LINQ
            OrderWithLINQ(students);
        }