请问C#允许两个分号; ;如果是的话,有没有什么特别的方法吗?的话、别的、分号、有没有什么

2023-09-02 01:37:19 作者:勿忘与他旳情

我写一个声明,它编译,但是编译器[VS]从来没有告诉我,我把分号两次。

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

这意味着在ASP.NET MVC 3

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?

如果有一个特殊的使用它,请告诉我,其中两个分号需要用C#编写的语句。

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

推荐答案

没有,一个双分号是从来没有要求。我微微一惊,编译器不抱怨,这是一个不可达的说法,但显然它是合法的。它不会做任何伤害,但同样它不是一个好主意。

No, a double semi-colon is never required. I'm slightly surprised that the compiler doesn't complain that it's an unreachable statement, but apparently it's legal. It won't do any harm, but equally it's not a good idea.