Advertisement
deleriumbg

Untitled

May 21st, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Find_Evens_or_Odds
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int[] boundaries = Console.ReadLine()
  12.                 .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  13.                 .Select(int.Parse)
  14.                 .ToArray();
  15.             List<int> numbers = new List<int>();
  16.  
  17.             for (int i = boundaries[0]; i <= boundaries[1]; i++)
  18.             {
  19.                 numbers.Add(i);
  20.             }
  21.             string command = Console.ReadLine();
  22.  
  23.             Func<int, bool> predicate;
  24.  
  25.             switch (command)
  26.             {
  27.                 case "even":
  28.                     predicate = x => x % 2 == 0;
  29.                     break;
  30.                 case "odd":
  31.                     predicate = x => x % 2 == 1;
  32.                     break;
  33.                 default:
  34.                     predicate = null;
  35.                     break;
  36.             }
  37.             Console.WriteLine(string.Join(" ", numbers.Where(predicate)));
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement