示例#1
0
        static void Main(string[] args)
        {
            StudentData sd = new StudentData();
            // List<Student> students = sd.GetFilteredStudents();
            List <Student> students = sd.GetAllStudents();
            List <String>  fruits   = new List <string> {
                "appel", "pear", "banana", "strawberry", "lemon"
            };

            foreach (string fruit in fruits)
            {
                // Console.WriteLine(fruit.ToUpper());
                ConvertString toCaps      = x => x.ToUpper();
                CountString   countString = x => x.Count();
                Console.WriteLine(toCaps(fruit) + " telt " + countString(fruit) + " tekens");
                // Console.WriteLine(fruit + " telt " + fruit.Count() + " tekens");
            }
            Console.WriteLine();
            for (int i = 0; i < fruits.Count() - 1; i++)
            {
                CheckString checkString = (x, y) => x.Count() > y.Count();
                Console.WriteLine(fruits[i] + " contains more characters then " + fruits[i + 1] + ": " + checkString(fruits[i], fruits[i + 1]));
            }
            Console.WriteLine();
            foreach (Student student in students)
            {
                CheckAge checkAge = (x, y) => x.Age >= y;
                Console.WriteLine(student.FirstName + " " + student.LastName + " is " + (checkAge(student, 21) ? "" : "not ") + "old enough.");
            }
            Console.ReadKey();
        }
        static void Report(string title, List <Person> people, CheckAge check)
        {
            Console.WriteLine(title);

            foreach (Person p in people)
            {
                if (check(p))
                {
                    Console.WriteLine("{0} is {1} years old", p.Name, p.Age);
                }
            }
        }
示例#3
0
        public void CalcAgeTest()
        {
            var sources = new RssSources(fileName);

            Assert.AreEqual(sources.Sources.Count, rssSourcesCount, $"Sources file count {sources.Sources.Count} != {rssSourcesCount}");

            foreach (var source in sources.Sources)
            {
                var uri = source.Value;
                using var feed = new RssFeed(uri);
                Assert.IsTrue(feed.Load());
                Assert.IsTrue(feed.PubDate > DateTimeOffset.MinValue);

                Console.WriteLine(feed);
            }

            using var aging = new CheckAge()
                  {
                      CurrentDateTime = DateTimeOffset.Now,
                      MaxAge          = TimeSpan.FromDays(2),
                      Feeds           = sources.Sources
                  };

            aging.Check();

            var companyEnum = sources.Sources.Keys.GetEnumerator();

            foreach (var isOverAge in aging.OverAge)
            {
                string companyName = "<unknown>";
                if (companyEnum.MoveNext())
                {
                    companyName = companyEnum.Current;
                }
                Console.WriteLine($"\"{companyName}\" RSS Feed is{(isOverAge?" ":" not ")}over {aging.MaxAge.Days} days");
            }
        }