Hello, I understand that the question is elementary for the majority - I am a newcomer, I will be grateful for reasonable answers. There is this code, how more correctly ( from the side of optimizing memory consumption ) will make a return to the menu of the selection of available program functions, which is in the void SwitchMessage () method, after execution.
As I understand it, there are 3 options:
Recursion inside SwitchMessage ();
goto;
The way that is now implemented in the code.
.
namespace ConsoleApp5 { class Program { Book book = new Book(); void Main() { Programin(1); } void WellcomeMessage () { Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Личная Библиотека"); } void SwitchMessage () { int inputSwitchDone; Block1: Console.WriteLine("Для просмотра существующих Книг - введите 1"); Console.WriteLine("Для добавления новой книги - введите 2"); string inputSwitch = Console.ReadLine(); if (int.TryParse(inputSwitch, out inputSwitchDone)) { //SwitchMessage (); //goto Block1; book.Switcher(inputSwitchDone); Programin(2); } else { ErrorMessage(); } Console.ReadKey(); } void Programin(int switch1) { switch (switch1) { case 1: WellcomeMessage(); SwitchMessage(); break; case 2: SwitchMessage(); break; default: break; } } void ErrorMessage () { Console.WriteLine("Введен Неверный тип данных, повторите ввод"); SwitchMessage(); } } }