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?
There isn’t anything deep, it’s a common thing accepted by compilers of many (but not all) languages. This makes doing lists easier:
When you want to add
Z = 0, you don’t need to edit the previous line to add a comma. This improves source code control deltas, because there is only one new line instead of one new line and one changed line.