This one has always puzzled me, but i'm guessing there is a very sensible explanation of why it happens.
When you have a collection initializer the compiler allows a trailing comma, e.g.
new Dictionary<string, string>
{
{ "Foo", "Bar "},
};
and
new List<string>
{
"Foo",
};
Anyone know why this trailing comma is allowed by the compiler?
Probably mainly for tools like code generators, where is it hugely convenient not to have to know if this is the first or last item. Arguably this shouldn't be a determining factor, but (having written such tools) I am grateful for it.
Similar reason to .NET Enumeration allows comma in the last field
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