Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Student
- {
- public int Mark;
- public string Class;
- public string Surname;
- // _class если будет не передан, будет изначально равен 11А
- public Student(int mark, string surname, string _class="11A")
- {
- // Инициализация полей через конструктор с 3 параметрами
- Mark = mark;
- Class = _class;
- Surname = surname;
- }
- public override string ToString() => Surname;
- }
- class Auto
- {
- public int Hp;
- public int Price;
- public Auto(int hp, int price=100)
- {
- Price = price;
- Hp = hp;
- }
- }
- class MainClass
- {
- public static void Main(string[] args)
- {
- List<Student> students = new List<Student>()
- {
- new Student(1,"Даня","П-32"), new Student(5, "Someone"), new Student(8, "Ураг гро-шуб", "Орк"),
- new Student(5,"Мой тиммейт", "1A"), new Student(5, "Я заебался пихать студентов"), new Student(10, "Дальше сам"),
- };
- // String.Join складывает все элементы массива через разделитель. Пример string.Join(">>>",[A, B, C]) => "A >>> B >>> C"
- Console.WriteLine("Студенты с оценкой 5: \n" + string.Join("\n", students.Where(x => x.Mark == 5).ToList()));
- List<Auto> autos = new List<Auto>()
- {
- 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),
- new Auto(290, 100)
- };
- Console.WriteLine("Общая сумма цен автомобилей с лошадиными силами больше 100: " + autos.Where(x => x.Hp > 100).Sum(x => x.Price));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement