
04-25-2011, 04:06 PM
|
 |
Ultimate Contributor
Preferred language: C#, VB
|
|
Join Date: Jun 2003
Location: USA
Posts: 2,096
|
|
Re: trying to understand syntax
Quote:
Originally Posted by jimmythefloyd
Is it just just some kind quirky thing?
|
The short answer is yes.
This syntax is inherited from C. It does seem inconsistent. However, consider the structure of the for statement (not sure if this is 100% technically correct, but it gets the idea across):
Code:
for (statement; expression; expression)
statement
Normally, a semi-colon denotes the end of a statement. As you can see, the last two are expressions. In this case, we are using the semi-colon as more of a delimiter. You don't normally write code with a trailing delimiter.
At the same time, C# does accept trailing commas in some cases. One reason for this is because it makes code generation simpler. (I use trailing commas in enums and initializers if they are declared across multiple lines.)
Code:
int[] x = {0, 1, 2, 3, };
var x = new { A = "Aye", B = "Bee", };
enum x {a, b, c, }
|
__________________
|