Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. class Student
  2. {
  3. public int Mark;
  4. public string Class;
  5. public string Surname;
  6.  
  7. // _class если будет не передан, будет изначально равен 11А
  8. public Student(int mark, string surname, string _class="11A")
  9. {
  10. // Инициализация полей через конструктор с 3 параметрами
  11. Mark = mark;
  12. Class = _class;
  13. Surname = surname;
  14. }
  15.  
  16. public override string ToString() => Surname;
  17. }
  18.  
  19. class Auto
  20. {
  21. public int Hp;
  22. public int Price;
  23.  
  24. public Auto(int hp, int price=100)
  25. {
  26. Price = price;
  27. Hp = hp;
  28. }
  29. }
  30.  
  31. class MainClass
  32. {
  33. public static void Main(string[] args)
  34. {
  35. List<Student> students = new List<Student>()
  36. {
  37. new Student(1,"Даня","П-32"), new Student(5, "Someone"), new Student(8, "Ураг гро-шуб", "Орк"),
  38. new Student(5,"Мой тиммейт", "1A"), new Student(5, "Я заебался пихать студентов"), new Student(10, "Дальше сам"),
  39. };
  40.  
  41. // String.Join складывает все элементы массива через разделитель. Пример string.Join(">>>",[A, B, C]) => "A >>> B >>> C"
  42. Console.WriteLine("Студенты с оценкой 5: \n" + string.Join("\n", students.Where(x => x.Mark == 5).ToList()));
  43.  
  44. List<Auto> autos = new List<Auto>()
  45. {
  46. new Auto(200), new Auto(300,200), new Auto(100, 300), new Auto(410, 1000), new Auto(50,10), new Auto(10, 10), new Auto(100, 10),
  47. new Auto(290, 100)
  48. };
  49.  
  50.  
  51. Console.WriteLine("Общая сумма цен автомобилей с лошадиными силами больше 100: " + autos.Where(x => x.Hp > 100).Sum(x => x.Price));
  52.  
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement