Was surprised to see that a C# Enum definition seems to allow an extra comma at the end (at least in VS2010).
e.g. :
public enum EnumTest1
{
Abc,
Def,
}
i.e. there is a comma at the end of "Def". Just wondering if this is allowed by design, or is an oversight. (This might be good to know, because if it is a bug, there may be no guarantees that code like the above will compile in future versions of C#).
It is allowed by design. Similarly, you can have trailing commas in initializers as well. For example:
var ints = new[] { 2, 3, 4, 3, };
var obj = new SomeClass { Prop1 = "foo", Prop2 = "bar", };
I think that allowing trailing commas makes creating auto-generated code much easier because you don't have to add last-in-the-list logic when outputting a list in your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With