Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _7._Predicate_for_Names
- {
- class Program
- {
- static void Main(string[] args)
- {
- //---------------------------- Variant vol. 1------------------------------------------
- //int nameLenght = int.Parse(Console.ReadLine());
- //List<string> allNames =
- // new List<string>(Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToList());
- //Func<List<string>, int, List<string>> func = (collection, length) =>
- // collection.Where(n => n.Length <= nameLenght).ToList();
- //allNames = func(allNames, nameLenght);
- //Console.WriteLine(string.Join(Environment.NewLine, allNames));
- //------------------------------ Variant vol. 2------------------------------------------
- int length = int.Parse(Console.ReadLine());
- string[] allNames = Console.ReadLine().Split();
- Action<string[]> printNames = name =>
- {
- Predicate<string> validatePredicate = currName => currName.Length <= length;
- foreach (var currentName in allNames.Where(n => validatePredicate(n)))
- {
- Console.WriteLine(currentName);
- }
- };
- printNames(allNames);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement