C# · 12月 25, 2021

c#这个设计是“正确的”吗?

我目前有以下内容 if (!RunCommand(logonAsAServiceCommand)) return; if (!ServicesRunningOrStart()) return; if (!ServicesStoppedOrHalt()) return; if (!BashCommand(CreateRuntimeBashCommand)) return; if (!ServicesStoppedOrHalt()) return; if (!BashCommand(BootstrapDataBashCommand)) return; if (!ServicesRunningOrStart()) return;

这样做会更干净吗?这样安全吗?

if ( (RunCommand(logonAsAServiceCommand)) && (ServicesRunningOrStart()) && (ServicesStoppedOrHalt()) && (BashCommand(CreateRuntimeBashCommand)) && (ServicesStoppedOrHalt()) && (BashCommand(BootstrapDataBashCommand)) && (ServicesRunningOrStart()) ) { // code after “return statements” here }解决方法 你应该坚持任何更具可读性和可理解性的东西.

除非它真的效率低下.