C# program to show how we can use enumeration to define symbolic constants for color

Category > CSHARP || Published on : Monday, November 16, 2020 || Views: 671 || use enumeration to define symbolic constants for color


Here Pawan Kumar will explain how to show how we can use enumeration to define symbolic constants for color

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication21
{
    class Colors
    {
        enum Color
        {
            Voilet,
            Green,
            Blue,
        }
        static void Main(string[] args)
        {
            string buffer;
            Color myColor;
            Console.WriteLine("Violet=0");
            Console.WriteLine("Green=1");
            Console.WriteLine("Blue=2");
            Console.WriteLine("Enter a value for a color:");
            buffer = Console.ReadLine();
            myColor = (Color)Convert.ToInt32(buffer);

            switch (myColor)
            {
                case Color.Voilet:
                	System.Console.WriteLine("\nYour choice of colour is:...");
                	break;
                case Color.Green:
                  	 System.Console.WriteLine("\nYour choice of colour is...");
            	 break;
                case Color.Blue:
                  	 System.Console.WriteLine("\nYour choice of colour is...");
            	 break;
                default:
                 	 System.Console.WriteLine("\nYour choice of colour is...");
            	 break;
            }
            System.Console.WriteLine("\n {0} ({1})", myColor, (int)myColor);
            Console.WriteLine("thanks!!");
            Console.Read();
        }
    }
}