Wednesday, August 14, 2013

Enum Purpose in C#.Net?

                 In this article i would like to publish an article on "Enum Purpose in C#.Net".

                                The enum keyword is used to declare an enumeration, a distinct type that consists of a set of named constants called the enumerator list.
    Enum is one of the user defined data type.Always enum can be declared in the global declaration.
                     Enum is a collection of key and associated pair values.
Usually it is best to define an enum directly within a namespace so that all classes in the namespace can access it with equal convenience. However, an enum can also be nested within a class or struct.
By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1.


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

namespace Interv
    public class EnumSample
        enum Days { Sun, Mon, Tue, Wed, Thu, Fri, Sat };

        static void Main()
            int a = (int)Days.Sun;
            int b = (int)Days.Mon;
            int c = (int)Days.Tue;
            int d = (int)Days.Wed;
            int e = (int)Days.Thu;
            int f = (int)Days.Fri;
            int g = (int)Days.Sat;
            Console.WriteLine("Sun = {0}",a);
            Console.WriteLine("Mon = {0}",b);
            Console.WriteLine("Tue = {0}",c);
            Console.WriteLine("Wed = {0}",d);
            Console.WriteLine("Thu = {0}",e);
            Console.WriteLine("Fri = {0}",f);
            Console.WriteLine("Sat = {0}",g);
            Console.WriteLine("This is about enum");
            Console.WriteLine("Keep Visiting this blog");

Enum in C#.Net

No comments: