public static void Main() { var input = Console.ReadLine().Split(); var list = new List <string>(); if (input.Length > 1) { for (int i = 1; i < input.Length; i++) { var currentElement = input[i]; list.Add(currentElement); } } var iterator = new ListyIterator <String>(list); while (true) { var command = Console.ReadLine(); if (command == "END") { break; } if (command == "Move") { Console.WriteLine(iterator.Move()); } else if (command == "Print") { iterator.Print(); } else if (command == "HasNext") { Console.WriteLine(iterator.HasNext()); } else if (command == "PrintAll") { Console.WriteLine(string.Join(" ", list)); } } }
static void Main() { var items = new ListyIterator <string>(Console.ReadLine().Split().Skip(1).ToArray()); try { string line; while ((line = Console.ReadLine()) != "END") { var tokens = line.Split(); switch (tokens[0]) { case "HasNext": Console.WriteLine(items.HasNext()); break; case "Move": Console.WriteLine(items.Move()); break; case "Print": items.Print(); break; case "PrintAll": var sb = new StringBuilder(); foreach (var item in items) { sb.Append(item + " "); } Console.WriteLine(sb.ToString().TrimEnd()); break; } } } catch (InvalidOperationException e) { Console.WriteLine(e.Message); } }