enum type

An enum type defines a group of constants. Each constant has a name and backend numeric value.

An enum is a value type.

The operators that work with enums are: = == != < > <= >= + - ^ & | ? += -= ++ - sizeof.

The following code defines an enum type wor week day:


using System;
enum WeekDay{
   Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
}


class Test
{
    static void Main()
    {
        WeekDay day = WeekDay.Monday;
        Console.WriteLine(day);

    }
}

The output:


Monday

We can also compare the enum value.


using System;
enum WeekDay{
   Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
}

class Test
{
    static void Main()
    {
        WeekDay day = WeekDay.Monday;
        WeekDay day2 = WeekDay.Tuesday;

        Console.WriteLine(day > day2);

        if (day == WeekDay.Monday)
        {
            Console.WriteLine("it is monday");
        }

    }
}

The output:


False
it is monday
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.