State Street Gang
.NET, straight up

Does this compile?

February 17, 2009 09:34 by will

Taking a momentary break from an internal beta...

Does this compile?

var foo = new FooType()

    {

        AnInt = 1,

        AnotherInt = 1,

        MyBar = bar,

    };

 

If you're wondering what's strange here, its the pointless last comma in the type initializer.

 

Apparently, the compiler doesn't care.  Which is a good thing, if you're lazy.  However, it could be an indication that you've forgotten something.

 

I'm voting its a bug in the compiler.

 


Tags:
Categories: C# | CLR
Actions: E-mail | Permalink | Comments (1) | Comment RSSRSS comment feed

Related posts

Comments

March 9. 2009 15:04

Mehrdad Afshari

Nope, this is not a bug. This is clearly specified in the language spec and the reason is to help automated generated files and ease of manipulation. This is also true for array initializers. The compiler will ignore the last comma. I think this behavior also exists in C++ compilers.

Mehrdad Afshari

Comments are closed