An empty-statement does nothing.
empty-statement:
;
An empty statement is used when there are no operations to perform in a
context where a statement is
required.
Execution of an empty statement simply transfers control to the end point
of the statement. Thus, the end
point of an empty statement is reachable if the empty statement is
reachable.
[Example: An empty statement can be used when writing a while statement
with a null body:
bool ProcessMessage() {?}
C# LANGUAGE SPECIFICATION
180
void ProcessMessages() {
while (ProcessMessage())
;
}
Also, an empty statement can be used to declare a label just before the
closing ?}? of a block:
void F() {
?
if (done) goto exit;
?
exit: ;
}
end example]
empty-statement:
;
An empty statement is used when there are no operations to perform in a
context where a statement is
required.
Execution of an empty statement simply transfers control to the end point
of the statement. Thus, the end
point of an empty statement is reachable if the empty statement is
reachable.
[Example: An empty statement can be used when writing a while statement
with a null body:
bool ProcessMessage() {?}
C# LANGUAGE SPECIFICATION
180
void ProcessMessages() {
while (ProcessMessage())
;
}
Also, an empty statement can be used to declare a label just before the
closing ?}? of a block:
void F() {
?
if (done) goto exit;
?
exit: ;
}
end example]
本文介绍了C#中空语句的使用方法及其应用场景。空语句在没有操作需要执行的情况下仍然保持语法结构完整,常用于while循环的空体定义或是作为标签声明。
1万+

被折叠的 条评论
为什么被折叠?



