static void Main(string[] args) { var container = new TaskContainer(); ITaskExample example = null; while ((example = container.GetTaskExample()) != null) { example.Execute(); Console.WriteLine("Example is processed"); } }
public ITaskExample GetTaskExample() { Console.WriteLine("\n"); int nmb = -1; ITaskExample result = null; while (nmb == -1) { Console.WriteLine("Type number of the example or \"exit\""); int i = 0; foreach (var taskExample in _examples) { ++i; Console.WriteLine($"{i}.\t{taskExample.Description}"); } string input = Console.ReadLine().ToUpper(); if (input == "EXIT") { nmb = int.MaxValue; break; } try { nmb = Convert.ToInt32(input) - 1; if (nmb < 0 || nmb >= _examples.Count) { Console.WriteLine("Number is out of range"); nmb = -1; } else { result = _examples[nmb]; break; } } catch (Exception) { Console.WriteLine("Number can't be parsed"); nmb = -1; } } return(result); }