Advertisement
illiden

Stew

Jul 11th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.ComponentModel;
  6.  
  7. namespace Lesson1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<Stew> stews = new List<Stew>()
  14.             {
  15.                 new Stew("Свинина", 2012, 20),
  16.                 new Stew("Говядина", 2016, 25),
  17.                 new Stew("Килька", 2020, 15),
  18.                 new Stew("Свинина", 2003, 20),
  19.                 new Stew("Сгущенка", 2017, 2),
  20.                 new Stew("Свинина", 2006, 20),
  21.                 new Stew("Свинина", 1970, 20),
  22.                 new Stew("Говядина", 2015, 25),
  23.                 new Stew("Килька", 1997, 15),
  24.                 new Stew("Сгущенка", 2019, 2),
  25.             };
  26.  
  27.             foreach (var stew in stews)
  28.             {
  29.                 Console.WriteLine($"{stew.Name} - {stew.ProducrionYear} года хранится {stew.ExpirationYear} лет");
  30.             }
  31.  
  32.             var expiredStew = stews.Where(stew => stew.ProducrionYear + stew.ExpirationYear <= DateTime.Now.Year);
  33.  
  34.             Console.WriteLine("\nПросрочены: ");
  35.             foreach (var stew in expiredStew)
  36.             {
  37.                 Console.WriteLine($"{stew.Name} - {stew.ProducrionYear} года хранится {stew.ExpirationYear} лет");
  38.             }
  39.             Console.ReadKey();
  40.         }
  41.     }
  42.  
  43.     class Stew
  44.     {
  45.         public string Name;
  46.         public int ProducrionYear;
  47.         public int ExpirationYear;
  48.  
  49.         public Stew(string name, int producrionDate, int expirationYear)
  50.         {
  51.             Name = name;
  52.             ProducrionYear = producrionDate;
  53.             ExpirationYear = expirationYear;
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement