Does C# allow double semicolon ; ; if so, are ther

2019-01-06 23:04发布

I am writing a statement and it compiles, but the compiler [VS] never tells me that I put the semicolon two times.

This means in ASP.NET MVC 3

return Json(mydata);;

return Json(mydata);

Both of them compile, but the first is wrong in design pattern. Why doesn't it tell me about the two semicolons.

If there is no reason to use two semicolons, why doesn't it show an error?

If there is a special use of it, please show me where two semicolons is required to write a statement in C#.

7条回答
不美不萌又怎样
2楼-- · 2019-01-07 00:02

; - statement separator. Double semicolon contains empty statement, which do nothing.

Using empty statement:

while (Method())
   ;

Or

void F() {
   //...
   if (done) goto exit;
   //...
   exit: ;
}

As you can see, this behavior is correct. But in your example you will have unreachable code with empty statement.

查看更多
登录 后发表回答