Missing last item on enums

c#, enums, visual-studio-2008

Solution

The trailing comma after the last `enum` member is optional. This was presumably done to aid automatic code generation which can just spit out stuff without thinking about the grammar.

Whether the comma is present or not doesn't change anything.

Take a look at the grammar:

enum-declaration: attributesopt enum-modifiersopt `enum` identifier enum-baseopt enum-body `;`opt

enum-base: `:` integral-type

enum-body: `{` enum-member-declarationsopt `}` `{` enum-member-declarations `,` `}`

enum-member-declarations: enum-member-declaration enum-member-declarations `,` enum-member-declaration

enum-member-declaration: attributesopt identifier attributesopt identifier `=` constant-expression

As you see, the enum-body includes the option of a single trailing comma.

Problem

I was looking for some enums options, and just spotted a missing comma after last option. Take, for instance, that `DayOfWeek` enum (press `F12` to go to definition): ``` public enum DayOfWeek { Sunday = 0, Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6, // note this comma } ``` Are there any reason behind this behavior?

Original source