Загрузка данных


using System;
using System.Collections.Generic;

class BrowserHistory
{
    static void Main()
    {
        Stack<string> history = new Stack<string>();
        string input;

        Console.WriteLine("Браузерная история. Введите URL или 'назад' для перехода, 'exit' для выхода.");

        while (true)
        {
            Console.Write("> ");
            input = Console.ReadLine().Trim();

            if (string.IsNullOrEmpty(input))
                continue;

            if (input.Equals("назад", StringComparison.OrdinalIgnoreCase))
            {
                if (history.Count > 1)
                {
                    history.Pop(); // удаляем текущую страницу
                    Console.WriteLine($"Переход на предыдущую страницу: {history.Peek()}");
                }
                else if (history.Count == 1)
                {
                    Console.WriteLine("Нет предыдущей страницы. Вы на первой странице.");
                }
                else
                {
                    Console.WriteLine("История пуста. Сначала откройте страницу.");
                }
            }
            else if (input.Equals("exit", StringComparison.OrdinalIgnoreCase))
            {
                Console.WriteLine("Выход.");
                break;
            }
            else
            {
                history.Push(input);
                Console.WriteLine($"Открыта страница: {input}");
            }

            // вывод текущей страницы
            if (history.Count > 0)
                Console.WriteLine($"Текущая страница: {history.Peek()}");
            else
                Console.WriteLine("Нет открытых страниц.");

            Console.WriteLine();
        }
    }
}