Advertisement
Guest User

Untitled

a guest
May 5th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. public static class Enumerating
  7. {
  8. class Student
  9. {
  10. public int Number { get; set; }
  11. public string Name { get; set; }
  12. public bool HasQuit { get; set; }
  13. public int Grade { get; set; }
  14. }
  15.  
  16. static List<Student> students = new List<Student>()
  17. {
  18. new Student { Number = 1111, Name = "Afonso", HasQuit = false, Grade = 16 },
  19. new Student { Number = 2222, Name = "Sancho", HasQuit = true },
  20. new Student { Number = 3333, Name = "Dinis", HasQuit = false, Grade = 13 },
  21. new Student { Number = 4444, Name = "Pedro", HasQuit = false, Grade = 17 },
  22. new Student { Number = 5555, Name = "Fernando", HasQuit = true },
  23. };
  24.  
  25. static void ForEach<T>(this IEnumerable<T> items, Action<T> action)
  26. {
  27. foreach (T item in items) action(item);
  28. }
  29.  
  30. static void Show(IEnumerable<Student> data)
  31. {
  32. data.Where(s => !s.HasQuit).OrderBy(s => s.Grade).Select(s => s.Name).ForEach(Console.WriteLine);
  33. }
  34.  
  35. public static void Main(string[] args)
  36. {
  37. Show(students);
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement