Wednesday, July 22, 2015

Enumerations - Facts

    Used to allow the user to assign any of the value from a specific list of value, into a data member/variable.
  • ·   It’s a collection of Constant Values.
  • ·         By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1. For example, in the following enumeration, Sat is 0, Sun is 1, Mon is 2, and so forth.
  • ·         enum Days {Sat, Sun, Mon, Tue, Wed, Thu, Fri};
  • ·         Variables cannot be assigned to enum elements.
  • ·         Float CANNOT be used as an underlying datatype for an enum
  • ·         Enum is Value Type.

using System;
namespace Enum
{
   public  enum AgeGroupEnum
    {
        Child, Tennager, Adult, Senior
    }
    class Person
    {
        public string Name { get; set; }
       public  AgeGroupEnum AgeGroup { get; set; }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Person p1 = new Person();
            p1.Name = "Soumik";
            p1.AgeGroup = AgeGroupEnum.Adult;

            Person p2 = new Person();
            p2.Name = "John";
            p2.AgeGroup = AgeGroupEnum.Senior;

            Console.WriteLine(p1.Name);
            Console.WriteLine(p2.Name);
            Console.WriteLine(p2.AgeGroup);
            Console.ReadKey();
        }
    }
}




No comments:

Post a Comment