Advertisement
bero_0401

Enums

Aug 18th, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | Source Code | 0 0
  1.  
  2. namespace CsharpCourse
  3. {
  4.  
  5.     internal class Program
  6.     {
  7.  
  8.         // enum
  9.         public enum Color
  10.         {
  11.             red,
  12.             green,
  13.             blue,
  14.             pink = 6,
  15.             white,
  16.             black
  17.         }
  18.  
  19.  
  20.  
  21.         static void Main(string[] args)
  22.         {
  23.             /*
  24.             foreach(var color in Enum.GetNames(typeof(Color)))
  25.             {
  26.                 Console.WriteLine($"{color} = {(int)Enum.Parse(typeof(Color) , color)}");
  27.             }
  28.             */
  29.  
  30.             while (true)
  31.             {
  32.                 Console.WriteLine("Select the BackGround Color");
  33.                 foreach (var color in Enum.GetNames(typeof(ConsoleColor)))
  34.                 {
  35.                     Console.WriteLine(color);
  36.  
  37.                 }
  38.                 string input = Console.ReadLine();
  39.                 ConsoleColor selectedColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), input, true);
  40.                 Console.BackgroundColor = selectedColor;
  41.             }
  42.         }
  43.  
  44.  
  45.  
  46.     }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement