Posted by : Anwar Hossain
Category : asp.net c # basic tutorial

Simple enum example in C Sharp

Dear viewers in this tutorial I will give a simple enumeration example .This example will give you a clear concept about enumeration in c# programming Language. C# enumerations are value data type that means enumeration contains only its own values inheritance is not possible. The enum keyword is used to declare an enumeration. A set of declared value can be assigned with enumeration. Initially the first enumerator is 0, and the value of each consecutive enumerator is increased by 1. In this example I have created a Holyday enum which content a set of day and used switch-case statement to find which day is holy day.

Simple Enum example in C #

 

Enum example in C Sharp

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace examleEnum

{

 

    class Program

    {

        static void Main(string[] args)

        {

 

            // create and initialize enum type

         

              Holiday MyHoliday = Holiday.Friday;

 

            //make decision

              switch (MyHoliday)

                  {

                      case Holiday.Friday:

                          Console.WriteLine("Yes today is Holiday take rest");

                        break;

                      case Holiday.Monday:

                        Console.WriteLine("Today is working day");

                        break;

                      case Holiday.Tuesday:

                        Console.WriteLine("Today is working day");

                        break;

                      case Holiday.Wednesday:

                        Console.WriteLine("Today is working day");

                        break;

                  }

                  Console.ReadLine();

        }

    }

    // declares the enum

    public enum Holiday

    {

        Monday,

        Tuesday,

        Wednesday,

        Thursday,

        Friday

    }

  

}

 

Out Put

C-Sharp-enum-example



Realted Article Headline

How to find odd number in c #
How to generate random number in c #
Nested For Loop Example in C Sharp
Store C sharp reference type in a List C#
Find number of items in a List C#
Concept about C # List
Custom Time formatting example C #
Custom Date formatting example C #
String Format Example using ASP.Net C#
Simple enum example in C Sharp
Nested switch-case statement example in C #
Combined switch...case statement example in C #
C Sharp switch case statement Example
C# SUM ArrayList Element Example
C# String Class Methods Example
C Sharp String Class Properties and Methods
C Sharp String Class Example
How to join two ArrayList collections in C#.
How to Use C Sharp Math Class
C Sharp ArrayList Property and Method
C Sharp ArrayList Example
C Sharp Arrays Example
C Sharp Logical operator Example
C Sharp Relational operators
C Sharp Arithmetic operators Example
C Sharp Common Assignment Operator
Simple for loop example in c sharp

Article Category

How to create asp.net control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in asp.net c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C#
asp.net c # basic tutorial
How to use ajax toolkit in asp.net C#
How to use different types of validation control using asp.net c#
How to use grid view in asp.net c#
Protected by Copyscape Online Plagiarism Detection