Advertisement
Legiomax

C#_2_lesson_console_menu

Jan 6th, 2024 (edited)
2,333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.80 KB | Software | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace C_Ijun
  8. {
  9.     internal class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             const string CommandClearWindow = "ClearWindow";
  14.             const string CommandTimeInfo = "Today is...";
  15.             const string CommandChangeColorText = "ChangeColorConsoleText";
  16.             const string CommandChangeColorBckg = "ChangeColorConsoleBackground";
  17.             const string CommandExit = "Exit";
  18.  
  19.             bool isWork = true;
  20.             string userChoice;
  21.  
  22.             while (isWork)
  23.             {
  24.                 Console.WriteLine("Консольное меню.");
  25.                 Console.WriteLine("Выбрать действие:");
  26.                 Console.WriteLine($"{CommandClearWindow} - Очистить экран.");
  27.                 Console.WriteLine($"{CommandTimeInfo} - Вывести день недели.");
  28.                 Console.WriteLine($"{CommandChangeColorText} - Изменить расветку текста консоли.");
  29.                 Console.WriteLine($"{CommandChangeColorBckg} - Изменить расветку фона консоли.");
  30.                 Console.WriteLine($"{CommandExit} - Выход.");
  31.  
  32.                 userChoice = Console.ReadLine();
  33.  
  34.                 switch (userChoice)
  35.                 {
  36.                     case CommandClearWindow:
  37.                         Console.Clear();
  38.                         break;
  39.  
  40.                     case CommandTimeInfo:
  41.                         Console.WriteLine(DateTime.Now);
  42.                         break;
  43.  
  44.                     case CommandChangeColorText:
  45.                         if (Console.ForegroundColor == ConsoleColor.Blue)
  46.                         {
  47.                             Console.ForegroundColor = ConsoleColor.Black;
  48.                         }
  49.                         else
  50.                         {
  51.                             Console.ForegroundColor = ConsoleColor.Blue;
  52.                         }
  53.                         break;
  54.  
  55.                     case CommandChangeColorBckg:
  56.                         Console.Clear();
  57.  
  58.                         if (Console.BackgroundColor == ConsoleColor.Blue)
  59.                         {
  60.                             Console.BackgroundColor = ConsoleColor.White;
  61.                         }
  62.                         else
  63.                         {
  64.                             Console.BackgroundColor = ConsoleColor.Blue;
  65.                         }
  66.                         break;
  67.  
  68.                     case CommandExit:
  69.                         Console.WriteLine("Это конец...");
  70.                         isWork = false;
  71.                         break;
  72.                 }
  73.             }
  74.         }
  75.     }
  76. }
  77.  
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement