从函数中提前返回
我有一个心理障碍,有人可以提醒我从函数提前返回的正确术语是什么,即
private MyObject DoSomeStuff(string myValue)
{
//What is this called?!?!?
if(myValue == string.Empty)
return null;
MyObject obj = new MyObject();
obj.Value = myValue;
return obj;
}
I'm having a mental block, can someone remind me what the correct term for returning early from a function is, i.e.
private MyObject DoSomeStuff(string myValue)
{
//What is this called?!?!?
if(myValue == string.Empty)
return null;
MyObject obj = new MyObject();
obj.Value = myValue;
return obj;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信这被称为保护条款。
I believe it's called a guard clause.
我可能会将其称为中断。或者,简单地说,提前返回。休息也可能有效。
I would potentially call this an Interrupt. Or, simply, and Early Return. Break might work, too.
我将其称为“前提条件测试”。
I would call it a "precondition test".