Choosing the default value of an Enum type without having to change values
Posted
by frou
on Stack Overflow
See other posts from Stack Overflow
or by frou
Published on 2009-02-09T20:59:20Z
Indexed on
2010/05/20
10:40 UTC
Read the original article
Hit count: 365
In C#, is it possible to decorate an Enum type with an attribute or do something else to specify what the default value should be, without having the change the values? The numbers required might be set in stone for whatever reason, and it'd be handy to still have control over the default.
enum Orientation
{
None = -1,
North = 0,
East = 1,
South = 2,
West = 3
}
Orientation o; // Is 'North' by default.
© Stack Overflow or respective owner