开发者

Weird line of c# code that works

return Json(new { ErrorMessag开发者_Python百科e = scheduleBase.ErrorMessage }, JsonRequestBehavior.AllowGet); ;

Is this just a weird case of me not being able to correctly see what the other semi-colon relates to? This code compiles and actually works fine, but I'm stumped as to why.

I found it in a co-workers code.


The extra semicolon is an empty statement after the return ...;.
It is useless and harmless.

Empty statements are useful as loop bodies:

while (str[++i] != '#')
    ;

They're also a common source of bugs:

if (something) ; 
{
    ...
}

This block is not connected to the if statement; the condition only applies to the empty statement.
The C# compiler will give a warning here.


Extra semicolons aren't errors.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜