first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

C#: Controlling the default value of an enum; MSDN

The default underlying type of the enumeration elements is int. By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1.

Enumerators can have initializers to override the default values. For example:

enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};

In this enumeration, the sequence of elements is forced to start from 1 instead of 0.

The default value of an enum E is the value produced by the expression (E)0.

In this example, the base-type option is used to declare an enum whose members are of the type long. Notice that even though the underlying type of the enumeration is long, the enumeration members must still be explicitly converted to type long using a cast.

// keyword_enum2.cs // Using long enumerators using System; public class EnumTest { enum Range :long {Max = 2147483648L, Min = 255L}; public static void Main() { long x = (long) Range.Max; long y = (long) Range.Min; Console.WriteLine("Max = {0}", x); Console.WriteLine("Min = {0}", y); } }

[http://msdn.microsoft.com/en-us/library/sbbt4032(VS.71).aspx]

mod date: 2009-08-15T02:45:34.000Z