Как избавиться от огромного блока if'ов

using System.Net;

namespace Program
{
    public static class Program
    {
        private static void DrawMenu(string[] items, int row, int col, int index)
        {
            Console.SetCursorPosition(col, row);
            for (int i = 0; i < items.Length; i++)
            {
                if (i == index)
                {
                    Console.BackgroundColor = Console.ForegroundColor;
                    Console.ForegroundColor = ConsoleColor.Black;
                }
                Console.WriteLine(items[i]);
                Console.ResetColor();
            }
            Console.WriteLine();
        }
        static void Main(string[] args)
        {
            string[] menuItems = new string[] { "P1", "P2" };

            Console.WriteLine("Меню");
            Console.WriteLine();

            int row = Console.CursorTop;
            int col = Console.CursorLeft;
            int index = 0;
            while (true)
            {
                DrawMenu(menuItems, row, col, index);
                switch (Console.ReadKey(true).Key)
                {
                    case ConsoleKey.DownArrow:
                        if (index < menuItems.Length - 1)
                            index++;
                        break;
                    case ConsoleKey.UpArrow:
                        if (index > 0)
                            index--;
                        break;
                    case ConsoleKey.Enter:
                        if (index == 0)
                        {

                        }
                        else if (index == 1)
                        {

                        }
                        break;
                }
            }
        }
    }
}

Как избавиться от огромного блока else if ? Если юзер выберет в этом меню пункт 1, то создается http запрос по первому url адресу, если выбирает пункт 2, то по другому url, и никакой проблемы бы не было если бы пунктов было 2-3, а если их будет 100 ? Что можно использовать вместо else if ?


Ответы (0 шт):