可能重复:
Single statement conditionals - why is the pattern not used for other code blocks?
C#: Why does Try-Catch require curly braces
这是一种C#编译器/语法问题:
为什么我们不能在C#中使用以下内容:
try
MethodCall() //Only one line here, of course
catch (Exception ex)
//Do a one-line action here
而不是
try {
MethodCall() //Only one line here, of course
}
catch (Exception ex) {
//Do a one-line action here
}
是否因为这会使C#语法模糊不清或类似的东西?
我只是好奇,因为我们可以完美地做到:
if (something)
Action1();
else
Action2();