C# program to show how we can use enumeration to define symbolic constants for on/off values

Category > CSHARP || Published on : Monday, November 16, 2020 || Views: 735 || use enumeration to define symbolic constants for on/off values


Here Pawan Kumar will explain how to show how we can use enumeration to define symbolic constants for on/off values

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication22
{
    class TTT
    {
        public enum Mode
        {
            off,
            on
        }
        static void Main(string[] args)
        {
            Mode ob;
            Console.WriteLine("enter 0 or 1");
            string str = Console.ReadLine();
            ob = (Mode)Convert.ToByte(str);

            if (ob == Mode.off)
                Console.WriteLine("off");
            else if (ob == Mode.on)
                Console.WriteLine("on");
            else
                Console.WriteLine("invalid number");
                Console.ReadLine();
        }
    }
}