Monday, 13 July 2015

[.]Dot Net Programs

WRITE A PROGRAM 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 choise of colour is:...");
                        break;
                case Color.Green:
                         System.Console.WriteLine("\nYour choise of colour is...");
                         break;
                case Color.Blue:
                         System.Console.WriteLine("\nYour choise of colour is...");
                         break;
                default:
                         System.Console.WriteLine("\nYour choise of colour is...");
                         break;
            }
            System.Console.WriteLine("\n {0} ({1})", myColor, (int)myColor);
            Console.WriteLine("thanks!!");
            Console.Read();
        }
    }
}