Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Enumeration in C#

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 78
    Comment on it

    Enumeration is a named value which is used to allocate various constant values to a single variable. This makes the program more easier to understand and maintain. Enumeration is also having better error checking techniques which additional security.
    An enumeration is defined by using enum keyword.

    Syntax of enumeration is:-

     enum enum_name
                {
                    enumeration list
                }; 

    Enumeration contains it's own values, it can not inherit and also does not proceed inheritance.

    Let us understand the enumeration with example:-

    using System;
    
    namespace enumprogram
    {
        public enum list { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }
    
        class Program
        {
            static void Main(string[] args)
            {
                list day = list.Tuesday;
                Console.WriteLine((int)day);
                Console.ReadLine();
            }
        }
    }
    

    output= 1(Because tuesday values to the number 1)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: