How to indicate that a method was unsuccessful

前端 未结 16 1522
走了就别回头了
走了就别回头了 2020-12-31 08:03

I have several similar methods, say eg. CalculatePoint(...) and CalculateListOfPoints(...). Occasionally, they may not succeed, and need to indicate this to the caller. For

16条回答
  •  Happy的楠姐
    2020-12-31 08:17

    Personally, I think I'd use the same idea as TryParse() : using an out parameter to output the real value, and returning a boolean indicating whether the call was successful or not

    public bool CalculatePoint(... out Point result);

    I am not a fan of using exception for "normal" behaviors (if you expect the function not to work for some entries).

提交回复
热议问题