开发者

Returning early from a function

开发者 https://www.devze.com 2023-04-08 04:43 出处:网络
I\'m having a mental block, can someone remind me what the correct term for returning early from a function is, i.e.

I'm having a mental block, can someone remind me what the correct term for returning early from a function is, i.e.

private MyOb开发者_StackOverflow中文版ject DoSomeStuff(string myValue)
{
    //What is this called?!?!?
    if(myValue == string.Empty)
        return null;

    MyObject obj = new MyObject();
    obj.Value = myValue;
    return obj;
}


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".

0

精彩评论

暂无评论...
验证码 换一张
取 消