static void Main(string[] args) { Student[] students = new Student[] { new Student("Filip", "Todorov", 22), new Student("Emil", "Stefanov", 19), new Student("Filip", "Kostadinov", 18), new Student("Vasil", "Ivanov", 24), new Student("Georgi", "Nikolov", 21), new Student("Petur", "Petrov", 27), new Student("Daniel", "Danailov", 17) }; var sorterWithLambda = students. OrderByDescending(student => student.FirstName). ThenByDescending(student => student.LastName); foreach (Student student in sorterWithLambda) { Console.WriteLine(student); } Console.Write("\n"); var sortedWithLinq = from student in students orderby student.FirstName descending, student.LastName descending select student; foreach (Student student in sortedWithLinq) { Console.WriteLine(student); } }
static IEnumerable<Student> FirstNameBeforeLast(Student[] students) { IEnumerable<Student> result = from student in students where student.FirstName.CompareTo(student.LastName) == -1 select student; return result; }
static void Main(string[] args) { Student[] students = new Student[] { new Student("Filip", "Todorov", 22), new Student("Emil", "Stefanov", 19), new Student("Vasil", "Ivanov", 24), new Student("Georgi", "Nikolov", 21) }; IEnumerable<Student> result = FirstNameBeforeLast(students); foreach (Student student in result) { Console.WriteLine(student); } }
static void Main() { Student student = new Student("Pesho", "Peshov", "Peshonkov", "ul. Krakra bl 20 ap 9", "0886004158", "Course", "8707133807", "*****@*****.**", Specialty.Informatics, University.NBU, Faculty.Mathematics); Student newStudent = student.Clone(); Console.WriteLine(student.CompareTo(newStudent)); Console.WriteLine(student == newStudent); newStudent.LastName = "Ivanov"; Console.WriteLine(student.CompareTo(newStudent)); Console.WriteLine(student != newStudent); Console.WriteLine(student); Console.WriteLine(newStudent); }
static void Main(string[] args) { Student[] students = new Student[] { new Student("Filip", "Todorov", 22), new Student("Emil", "Stefanov", 19), new Student("Vasil", "Ivanov", 24), new Student("Georgi", "Nikolov", 21), new Student("Petur", "Petrov", 27), new Student("Daniel", "Danailov", 17) }; var filtered = from student in students where student.Age >= 18 && student.Age <= 24 select student; foreach (var student in filtered) { Console.WriteLine(student); } }
static void Main() { Student[] students = new Student[] { new Student( "Jameson", "George", "Stuart", "012-213-432", "123 Picadilly square, London, United Kingdom", "020-3213-344", "*****@*****.**", 2, Speciality.Architecture, Faculty.Arts, University.Cambridge), new Student( "Peter", "Walker", "McCain", "012-213-436", "34 Downing Street, London, United Kingdom", "029-3442-1231", "*****@*****.**", 4, Speciality.Astronomy, Faculty.Environment, University.Harvard), new Student( "Layla", "Johnson", "Peterson", "012-213-543", "123 Portobello Road, London, United Kingdom", "159-3742-7831", "*****@*****.**", 2, Speciality.Physics, Faculty.Engineering, University.Edinburgh), new Student( "Misha", "Ilarionov", "Moskovskii", "455-31-5124", "Tverskaya Ulitsa, Moscow, Russia", "449-3412-4351", "*****@*****.**", 3, Speciality.Dentistry, Faculty.Medicine, University.Oxford), new Student( "Dasha", "Ivanovna", "Odeskaya", "344-45-5642", "345 Promorsky Bulvard, Odessa, Ukraine", "532-1233-8723", "*****@*****.**", 2, Speciality.Mathematics, Faculty.Engineering, University.Cambridge), }; Console.WriteLine("Original student:\n" + students[0]); Student cloned = students[0].Clone(); Console.WriteLine("Cloned student:\n{0}\n", cloned); Console.WriteLine("First and Cloned are the same students is {0}", students[0].Equals(cloned)); Array.Sort(students); foreach (Student student in students) { Console.WriteLine(student); } }