Kev*_*oyd 14 c# compilation codeblocks conditional-statements
C#如何编译?
if (info == 8)
info = 4;
otherStuff();
Run Code Online (Sandbox Code Playgroud)
它会包含代码块中的后续行吗?
if (info == 8)
{
info = 4;
otherStuff();
}
Run Code Online (Sandbox Code Playgroud)
或者它只需要下一行?
if (info == 8)
{
info = 4;
}
otherStuff();
Run Code Online (Sandbox Code Playgroud)
Jon*_*eet 43
是的,它支持它 - 但它需要下一个声明,而不是下一行.例如:
int a = 0;
int b = 0;
if (someCondition) a = 1; b = 1;
int c = 2;
Run Code Online (Sandbox Code Playgroud)
相当于:
int a = 0;
int b = 0;
if (someCondition)
{
a = 1;
}
b = 1;
int c = 2;
Run Code Online (Sandbox Code Playgroud)
就个人而言,我总是在if声明的主体周围加上括号,而且我遇到的大多数编码约定采用相同的方法.