View difference between Paste ID: 1XTi4u8G and 1qc4xtUM
SHOW: | | - or go back to the newest paste.
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
5
namespace LinqTrain
6
{
7
    class Program
8
    {
9
        public static void Main()
10
        {
11
            int yearNow = 2000;
12
            List<Stew> stews = new List<Stew>();
13
            for (int i = 0; i < 60; i++)
14
            {
15
                stews.Add(new Stew());
16
                Console.WriteLine(stews[i].GetInfo(yearNow));
17
            }
18
            Console.ReadKey();
19
            Console.Clear();
20
21-
            List<Stew> sortList = stews.Where(stew => stew.CheckFreshness(yearNow) == false).ToList<Stew>();
21+
            var listRancidStew = stews.Where(stew => stew.CheckFreshness(yearNow) == false);
22
            Console.WriteLine($"Год сейчас - {yearNow} \nВывод просроченной тушенки");
23-
            foreach (var stew in sortList)
23+
            foreach (var stew in listRancidStew)
24
            {
25
                Console.WriteLine(stew.GetInfo(yearNow));
26
            }
27
            Console.ReadKey();
28
        }
29
    }
30
    public static class RandomStatic
31
    {
32
        static private Random _rand = new Random();
33
        static public int GetNext(int min, int max)
34
        {
35
            return _rand.Next(min, max);
36
        }
37
    }
38
    public class Stew
39
    {
40
        public string Name { get; private set; }
41
        public int ProductionYear { get; private set; }
42
        public int ShelfLife { get; private set; }
43
        public Stew()
44
        {
45
            int index = RandomStatic.GetNext(0, 3);
46
            Name = new string[] { "Производитель 1", "Производитель 2", "Производитель 3" }[index];
47
            ProductionYear = new int[] { RandomStatic.GetNext(1970, 1975), RandomStatic.GetNext(1976, 1980), RandomStatic.GetNext(1980, 1985) }[index];
48
            ShelfLife = RandomStatic.GetNext(20, 35);
49
        }
50
        public bool CheckFreshness(int yearNow)
51
        {
52
            return ProductionYear + ShelfLife > yearNow;
53
        }
54
        public string GetInfo(int yearNow)
55
        {
56
            return $"{Name} - Произведена {ProductionYear} - срок годности {ShelfLife} - Истек {!CheckFreshness(yearNow)}";
57
        }
58
    }
59
}