Friday 25 January 2013

enum in c#


Enums store special values. They make programs simpler. If you place constants directly where used, your C# program becomes complex. It becomes hard to change. Enums instead keep these magic constants in a distinct type.

Example

In this first example, we see an enum type that indicates the importance of something. An enum type internally contains an enumerator list. You will use enum when you want readable code that uses constants.
An enum type is a distinct value type that declares a set of named constants.
Program that uses enums [C#]

using System;

class Program
{
    public enum PageName
    {
        Any = 0,
        Index = 1,
        About = 2
    }

    static void Main()
    {
     Console.WriteLine(PageName.Any);
 
    }
}

Output

0

No comments:

Post a Comment

If any doubt?then please comment in my post

How to reduce angular CLI build time

 Index: ----- I am using angular cli - 7 and I am going to tell how to reduce the build time as per my knowledge. Problem: -------- Now the ...