holllowknight

Просрочка

May 4th, 2023
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Tush
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<StewCan> stewCans = new List<StewCan>()
  12.             {
  13.                 new StewCan("Мясницкий ряд", 2020, 3),
  14.                 new StewCan("Останкино", 2021, 5),
  15.                 new StewCan("Папа может", 2019, 5),
  16.                 new StewCan("Микоян", 2005, 4),
  17.                 new StewCan("Черкизово", 2015, 3),
  18.                 new StewCan("Вязанка", 2018, 4),
  19.                 new StewCan("Батькин резерв", 2018, 3),
  20.                 new StewCan("Атяшево", 2020, 6),
  21.             };
  22.  
  23.             var expiredStewCans = stewCans.Where(stewCan => DateTime.Now.Year - stewCan.ProductYear > stewCan.ExpirationTime);
  24.  
  25.             foreach (var stewCan in expiredStewCans)
  26.                 stewCan.ShowInfo();
  27.         }
  28.     }
  29.  
  30.     class StewCan
  31.     {
  32.         public StewCan(string title, int productYear, int expirationTime)
  33.         {
  34.             Title = title;
  35.             ProductYear = productYear;
  36.             ExpirationTime = expirationTime;
  37.         }
  38.  
  39.         public string Title { get; private set; }
  40.         public int ProductYear { get; private set; }
  41.         public int ExpirationTime { get; private set; }
  42.  
  43.         public void ShowInfo()
  44.         {
  45.             Console.WriteLine($"{Title}, произведено: {ProductYear}, срок годности: {ExpirationTime}");
  46.         }
  47.     }
  48. }
  49.  
Add Comment
Please, Sign In to add comment