I often have several statements at the start of a method to return for "easy" situations.
(在方法开始时,我经常会有几条陈述返回“轻松”情况。)
For example, this: (例如,这:)
public void DoStuff(Foo foo)
{
if (foo != null)
{
...
}
}
... can be made more readable (IMHO) like this:
(...可以像这样变得更具可读性(IMHO):)
public void DoStuff(Foo foo)
{
if (foo == null) return;
...
}
So yes, I think it's fine to have multiple "exit points" from a function/method.
(所以是的,我认为从一个函数/方法中获得多个“退出点”是可以的。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…