Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Tush
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<StewCan> stewCans = new List<StewCan>()
- {
- new StewCan("Мясницкий ряд", 2020, 3),
- new StewCan("Останкино", 2021, 5),
- new StewCan("Папа может", 2019, 5),
- new StewCan("Микоян", 2005, 4),
- new StewCan("Черкизово", 2015, 3),
- new StewCan("Вязанка", 2018, 4),
- new StewCan("Батькин резерв", 2018, 3),
- new StewCan("Атяшево", 2020, 6),
- };
- var expiredStewCans = stewCans.Where(stewCan => DateTime.Now.Year - stewCan.ProductYear > stewCan.ExpirationTime);
- foreach (var stewCan in expiredStewCans)
- stewCan.ShowInfo();
- }
- }
- class StewCan
- {
- public StewCan(string title, int productYear, int expirationTime)
- {
- Title = title;
- ProductYear = productYear;
- ExpirationTime = expirationTime;
- }
- public string Title { get; private set; }
- public int ProductYear { get; private set; }
- public int ExpirationTime { get; private set; }
- public void ShowInfo()
- {
- Console.WriteLine($"{Title}, произведено: {ProductYear}, срок годности: {ExpirationTime}");
- }
- }
- }
Add Comment
Please, Sign In to add comment