The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,738 other followers

Archive for December 6th, 2012

C#: any c# – .NET Enumeration allows comma in the last field – Stack Overflow

Posted by jpluimers on 2012/12/06

Thanks Nick Craver for answering this on StackOverflow.

Array initializers can be specified in field declarations (§17.4), local variable declarations (§15.5.1), and
array creation expressions (§14.5.10.2).

The array initializer can end in a comma, which makes some things way easier (boy, I wish I had this in other programming languages).

From Nick’s answer:

It has no special meaning, just the way the compiler works, it’s mainly for this reason:

[FlagsAttribute]
public enum DependencyPropertyOptions : byte
{
Default = 1,
ReadOnly = 2,
Optional = 4,
DelegateProperty = 32,
Metadata = 8,
NonSerialized = 16,
//EnumPropertyIWantToCommentOutEasily = 32
}
[/language]By comment request: This info comes straight out of the ECMA C# Specification (Page 363/Section 19.7)

“Like Standard C++, C# allows a trailing comma at the end of an array-initializer. This syntax provides flexibility in adding or deleting members from such a list, and simplifies machine generation of such lists.”

–jeroen

via c# – .NET Enumeration allows comma in the last field – Stack Overflow.

Posted in .NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C++, Delphi, Development, Java, JavaScript/ECMAScript, PHP, Software Development, VB.NET | 5 Comments »

 
%d bloggers like this: