laughingblade
3/28/2014 - 10:27 AM

Demonstration of enums in C#

Demonstration of enums in C#

using System;

namespace ArgyleTestbed
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Enum.GetName(typeof(BuiltFormEnum), 4);
            Console.WriteLine(s);

            var house = BuiltFormEnum.House;
            var houseNumber = (int)house;
            Console.WriteLine("{0} is house number #{1}.", house, houseNumber);
            
            Console.WriteLine("The values of the BuiltFormEnum Enum are:");
            foreach (int i in Enum.GetValues(typeof(BuiltFormEnum)))
                Console.WriteLine(i);

            Console.WriteLine("The names of the BuiltFormEnum Enum are:");
            foreach (var str in Enum.GetNames(typeof(BuiltFormEnum)))
                Console.WriteLine(str);

            Console.ReadLine();
        }

    }

    public enum BuiltFormEnum
    {
        House = 1,
        Bungalow = 2,
        Flat = 3,
        Maisonette = 4
    }
}

/*Output:

Maisonette
House is house number #1.
The values of the BuiltFormEnum Enum are:
1
2
3
4
The names of the BuiltFormEnum Enum are:
House
Bungalow
Flat
Maisonette
*/