C# Empty Statement

后端 未结 13 2302
情深已故
情深已故 2020-11-29 12:34

The C# language specification defines the empty-statement grammar production, which allows me to do something like this:

static void Main(string[] a         


        
13条回答
  •  隐瞒了意图╮
    2020-11-29 12:56

    C# inherits a lot from the C family, where you can do things like

    for (i = 0; i < n; v[i++] = 1);
    

    or

    while (testSomeCondition());
    

    That is, run a loop with an empty body where the "meat" is inside the brackets.

    While one can debate about their merits and dangers, these are pretty common programming idioms in the C programming world, so this backward compatibility makes it easier for C/C++/Java programmers to learn C#.

提交回复
热议问题