예제 #1
0
 //Rewrite previous method with LINQ
 public static void SortStudentsByNameLINQ(Student[] students)
 {
     var sortedStudents =
         from student in students
         orderby student.firstName descending, student.secondName descending
         select student;
     PrintStudents(sortedStudents);
 }
예제 #2
0
 //finds all students whose first name is before its last name alphabetically
 public static void FindStudentsFirstNameBeforeSecond(Student[] students)
 {
     var foundStudents =
         from student in students
         where(student.firstName.CompareTo(student.secondName) < 0)
         select(student);
     PrintStudents(foundStudents);
 }
예제 #3
0
 //finds the first name and last name of all students with age between 18 and 24
 public static void FindStudentsBetween18And24(Student[] students)
 {
     var foundStudents =
         from student in students
         where student.age >= 18 && student.age <= 24
         select student;
     PrintStudents(foundStudents);
 }
예제 #4
0
 //Using the extension methods OrderBy() and ThenBy() with lambda expressions sort the students by first name
 //and last name in descending order.
 public static void SortStudentsByName(Student[] students)
 {
     var sortedStudents = students.OrderByDescending(student => student.firstName).
                                   ThenByDescending(student => student.secondName);
     PrintStudents(sortedStudents);
 }