为什么允许使用多个分号? [英] Why are multiple semicolons allowed?
本文介绍了为什么允许使用多个分号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下代码:
myBusiness business = new myBusiness();
business.DoWork(); ; ; ; ; ; ;
为什么要使用多个分号?
Why can we use multiple semicolons? Is it a bug in the compiler?
推荐答案
这是因为分号单独使用时表示 empty语句。
That's because the semicolon, when used alone, represents the empty statement.
文档说:
空语句由一个分号组成。它什么也不做
,可以在需要执行语句但不需要执行任何操作
的地方使用。
The empty statement consists of a single semicolon. It does nothing and can be used in places where a statement is required but no action needs to be performed.
并提供以下示例:
void ProcessMessages()
{
while (ProcessMessage())
; // Statement needed here.
}
当然,您可以按顺序执行任意数量的空语句,而且什么也不会发生。
Of course, you can execute as many empty statements as you want in sequence, and nothing will happen.
这篇关于为什么允许使用多个分号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文