123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- using System.Linq;
- List<Item> phones = new List<Item>()
- {
- new Item("Iphone SE 2020", 24000),
- new Item("Nokia 3310", 2000),
- new Item("Samsung Galaxy S24", 90000),
- new Item("Samsung Z Fold5", 65000),
- new Item("Iphone 15 Pro Max", 139000),
- new Item("Iphone X", 32000),
- new Item("Xiaomi 12T Pro", 60000)
- };
- /* 1
- var sorted = phones.OrderBy(x => x.title).ThenByDescending(x => x.price);
- foreach (var a in sorted)
- {
- Console.WriteLine(a.title +" - "+ a.price);
- }
- */
- /* 2
- var averageprice = phones.Select(u =>u.price).Average();
- Console.WriteLine(averageprice);
- */
- /* 3
- var sorted = phones.Where(u => u.title.StartsWith("Samsung"));
- foreach (var a in sorted)
- {
- Console.WriteLine(a.title);
- }
- Console.WriteLine();
- var sorted2 = phones.Where(u => u.title.StartsWith("Iphone"));
- foreach (var a in sorted2)
- {
- Console.WriteLine(a.title);
- }
- */
- /* 4
- var phoneslist = phones.OrderBy(x => x.price);
- foreach (var x in phoneslist)
- {
- Console.WriteLine(x.title +" - "+ x.price);
- }
- */
- var newlist = phones.Where(u => u.price < 50000).Select(u => u);
- Console.WriteLine("Смартфоны дешевле 50000:");
- foreach (var a in newlist)
- {
- Console.WriteLine(a.title +"-"+ a.price);
- }
- public class Category
- {
- public string title { get; set; }
- public Category(string title)
- {
- this.title = title;
- }
- }
- public class Item
- {
- public string title { get; set; }
- public Category category { get; set; }
- public string description { get; set; }
- public double price { get; set; }
- public Item (string title, double price)
- {
- this.title = title;
- this.price = price;
- }
- }
- public abstract class Person
- {
- public string firstName { get; set; }
- public string lastName { get; set; }
- public int age { get; set; }
- public Person(string firstName, string lastName, int age)
- {
- this.firstName = firstName;
- this.lastName = lastName;
- this.age = age;
- }
- }
- public class Worker : Person
- {
- public double salary { get; set; }
- public string position { get; set; }
- public Worker(string firstName, string lastName, int age, double salary, string position) : base(firstName, lastName, age)
- {
- this.salary = salary;
- this.position = position;
- }
- }
- public class Client : Person
- {
- public string numberPhone { get; set; }
-
- public Client(string firstName, string lastName, int age, string numberPhone) : base(firstName, lastName, age)
- {
- this.numberPhone = numberPhone;
- }
- }
|