The default value of any enum is zero. So if you want to set one enumerator to be the default value, then set that one to zero and all other enumerators to non-zero (the first enumerator to have the value zero will be the default value for that enum if there are several enumerators with the value zero).
enum Orientation
{
None = 0, //default value since it has the value '0'
North = 1,
East = 2,
South = 3,
West = 4
}
Orientation o; // initialized to 'None'
If your enumerators don't need explicit values, then just make sure the first enumerator is the one you want to be the default enumerator since "By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1." (C# reference)
enum Orientation
{
None, //default value since it is the first enumerator
North,
East,
South,
West
}
Orientation o; // initialized to 'None'
int
s in the abstract, simply because they happen to be implemented as a numeric types. We could implement enums as strings, and it would not change their usefulness. I consider the answer here a limitation of the expressiveness of the C# language; the limitation is certainly not inherent in the idea of "distinguishing values from a restricted set." – Torqueenum
s as type-level constructs, specifically as sum types (or see here. That is, consider each enum as a distinct type, where all values of that type are distinct from every other enum's values. From such a mindset, it is impossible for enums to share any value, and indeed, this abstraction falls apart when you consider that the default of0
may or may not be valid for a given enum, and is simply shoe-horned into every enum. – Torque