Why is the compiler not complaining about an additional ',' in Array or Object Initializers?

Posted by Danvil on Stack Overflow See other posts from Stack Overflow or by Danvil
Published on 2010-04-20T10:40:52Z Indexed on 2010/04/20 10:43 UTC
Read the original article Hit count: 219

Filed under:
|
|

Using simple type like

class A {
  public int X, Y;
}

with object intializers, one can write

var a = new A { X=0, Y=0 };

But the following is also accepted by the compiler:

var a = new A { X=0, Y=0, }; // notice the additional ','

Same for int[] v = new int[] { 1, 2, };

This looks a bit strange ... Did they forgot to reject the additional ',' in the compiler or is there a deeper meaning behind this?

© Stack Overflow or respective owner

Related posts about c#

Related posts about c#3.0