C# examples of enumeration

///////////// ENUMERATIONS  declaration /////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ConsoleApplication1
{
    
    class Program
    {
        public enum TimeOfDay
        {
            Morning=0, Afternoon=1, Evening=2
        }

        static void Main(string[] args)
        {
            TimeOfDay t = TimeOfDay.Evening;
            Console.WriteLine(t.ToString());
            //writeGreeting(TimeOfDay.Evening);
            
        }
        static void writeGreeting(TimeOfDay t)
        {
            switch (t)
            {
                case TimeOfDay.Morning:
                    Console.WriteLine("good morning");
                    break;

                case TimeOfDay.Afternoon:
                    Console.WriteLine("good afternoon");
                    break;

                case TimeOfDay.Evening:
                    Console.WriteLine("good evening");
                    break;
            }

        }
    }
}
//===================================================================


////// Enumeration examples

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ConsoleApplication1
{
    
    class Program
    {
        public enum TimeOfDay
        {
           option1, option2, option3
        }

        static void Main(string[] args)
        {
            int a=10;
            
            TimeOfDay t = TimeOfDay.option1;

            if(a>5 && a< 10)
            {
                t = TimeOfDay.option1;
            }
            else if(a>= 10 && a<15)
            {
                t = TimeOfDay.option2;
            }
            else if(a >= 15 && a<20)
            {
                t = TimeOfDay.option3;
            }
 
        if(t == TimeOfDay.option2)
            Console.WriteLine("This was only the right option");
        }
        

        }
    }

 

Add a Comment

Your email address will not be published. Required fields are marked *