Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace CSharpAdvanced
- {
- public class Person
- {
- public string Name { get; set; }
- public int Age { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- int number = int.Parse(Console.ReadLine());
- var people = new List<Person>();
- for (int i = 0; i < number; i++)
- {
- var input = Console.ReadLine()
- .Split(", ", StringSplitOptions.RemoveEmptyEntries);
- var person = new Person
- {
- Name = input[0],
- Age = int.Parse(input[1])
- };
- people.Add(person);
- }
- string condition = Console.ReadLine();
- int age = int.Parse(Console.ReadLine());
- Func<Person, bool> filterPredicate;
- if (condition == "older")
- {
- filterPredicate = p => p.Age >= age;
- }
- else
- {
- filterPredicate = p => p.Age < age;
- }
- string format = Console.ReadLine();
- Func<Person, string> printFunc;
- if (format == "name age")
- {
- printFunc = p => $"{p.Name} - {p.Age}";
- }
- else if (format == "name")
- {
- printFunc = p => $"{p.Name}";
- }
- else
- {
- printFunc = p => $"{p.Age}";
- }
- people
- .Where(filterPredicate)
- .Select(printFunc)
- .ToList()
- .ForEach(Console.WriteLine);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement