Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Data;
- namespace Definition_of_delay
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Storehouse storehouse = new Storehouse();
- storehouse.ShowStews();
- storehouse.FindDelayStew();
- Console.WriteLine();
- storehouse.ShowStews();
- }
- }
- class Stew
- {
- public Stew(string name, DateTime dateProduction, int expiration)
- {
- Name = name;
- DateProduction = dateProduction;
- Expiration = expiration;
- }
- public string Name { get; private set;}
- public DateTime DateProduction { get; private set;}
- public int Expiration { get; private set;}
- }
- class Storehouse
- {
- private List<Stew> _stews = new List<Stew>();
- public Storehouse()
- {
- _stews.Add(new Stew("Мясокомбинат Курганский", new DateTime(2020, 2, 27), 5));
- _stews.Add(new Stew("Главпродукт", new DateTime(2015, 8, 30), 3));
- _stews.Add(new Stew("Скопинский мясоперерабатывающий комбинат", new DateTime(2024, 3, 14), 2));
- _stews.Add(new Stew("Йошкар-Олинский мясокомбинат", new DateTime(2019, 4, 12), 1));
- _stews.Add(new Stew("Любимый дом", new DateTime(2021, 12, 3), 3));
- }
- public void ShowStews()
- {
- foreach (Stew stew in _stews)
- {
- Console.WriteLine($"Название - \"{stew.Name}\", дата производства - {stew.DateProduction.ToShortDateString()}, срок годности {stew.Expiration}");
- }
- }
- public void FindDelayStew()
- {
- DateTime today = DateTime.Today;
- _stews = _stews.Where(stew => stew.DateProduction.AddYears(stew.Expiration) <= today).ToList();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment