Advertisement
elena1234

PredicateForNames- how to use func<>

Jan 26th, 2021
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace PredicateForNames
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int length = int.Parse(Console.ReadLine());
  12.             string[] names = Console.ReadLine().Split().ToArray();
  13.             Func<int, string[], string[]> func = (length, names) =>
  14.               {
  15.                   var newList = new List<string>();
  16.                   foreach (var name in names)
  17.                   {
  18.                       if(name.Length <= length)
  19.                       {
  20.                           newList.Add(name);
  21.                       }
  22.                   }
  23.  
  24.                   return newList.ToArray();
  25.               };
  26.  
  27.             var newNames = func(length, names);
  28.             Console.WriteLine(string.Join(Environment.NewLine, newNames));
  29.         }
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement