Program.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System.Linq;
  2. List<Item> phones = new List<Item>()
  3. {
  4. new Item("Iphone SE 2020", 24000),
  5. new Item("Nokia 3310", 2000),
  6. new Item("Samsung Galaxy S24", 90000),
  7. new Item("Samsung Z Fold5", 65000),
  8. new Item("Iphone 15 Pro Max", 139000),
  9. new Item("Iphone X", 32000),
  10. new Item("Xiaomi 12T Pro", 60000)
  11. };
  12. /* 1
  13. var sorted = phones.OrderBy(x => x.title).ThenByDescending(x => x.price);
  14. foreach (var a in sorted)
  15. {
  16. Console.WriteLine(a.title +" - "+ a.price);
  17. }
  18. */
  19. /* 2
  20. var averageprice = phones.Select(u =>u.price).Average();
  21. Console.WriteLine(averageprice);
  22. */
  23. /* 3
  24. var sorted = phones.Where(u => u.title.StartsWith("Samsung"));
  25. foreach (var a in sorted)
  26. {
  27. Console.WriteLine(a.title);
  28. }
  29. Console.WriteLine();
  30. var sorted2 = phones.Where(u => u.title.StartsWith("Iphone"));
  31. foreach (var a in sorted2)
  32. {
  33. Console.WriteLine(a.title);
  34. }
  35. */
  36. /* 4
  37. var phoneslist = phones.OrderBy(x => x.price);
  38. foreach (var x in phoneslist)
  39. {
  40. Console.WriteLine(x.title +" - "+ x.price);
  41. }
  42. */
  43. var newlist = phones.Where(u => u.price < 50000).Select(u => u);
  44. Console.WriteLine("Смартфоны дешевле 50000:");
  45. foreach (var a in newlist)
  46. {
  47. Console.WriteLine(a.title +"-"+ a.price);
  48. }
  49. public class Category
  50. {
  51. public string title { get; set; }
  52. public Category(string title)
  53. {
  54. this.title = title;
  55. }
  56. }
  57. public class Item
  58. {
  59. public string title { get; set; }
  60. public Category category { get; set; }
  61. public string description { get; set; }
  62. public double price { get; set; }
  63. public Item (string title, double price)
  64. {
  65. this.title = title;
  66. this.price = price;
  67. }
  68. }
  69. public abstract class Person
  70. {
  71. public string firstName { get; set; }
  72. public string lastName { get; set; }
  73. public int age { get; set; }
  74. public Person(string firstName, string lastName, int age)
  75. {
  76. this.firstName = firstName;
  77. this.lastName = lastName;
  78. this.age = age;
  79. }
  80. }
  81. public class Worker : Person
  82. {
  83. public double salary { get; set; }
  84. public string position { get; set; }
  85. public Worker(string firstName, string lastName, int age, double salary, string position) : base(firstName, lastName, age)
  86. {
  87. this.salary = salary;
  88. this.position = position;
  89. }
  90. }
  91. public class Client : Person
  92. {
  93. public string numberPhone { get; set; }
  94. public Client(string firstName, string lastName, int age, string numberPhone) : base(firstName, lastName, age)
  95. {
  96. this.numberPhone = numberPhone;
  97. }
  98. }