How to indicate that a method was unsuccessful

前端 未结 16 1517
走了就别回头了
走了就别回头了 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条回答
  •  执笔经年
    2020-12-31 08:13

    The model I've used is the same one MS uses with the TryParse methods of various classes.

    Your original code:
    public Point CalculatePoint(... out Boolean boSuccess);
    public List CalculateListOfPoints(... out Boolean boSuccess);

    Would turn into public bool CalculatePoint(... out (or ref) Point CalculatedValue);
    public bool CalculateListOfPoints(... out (or ref) List CalculatedValues);

    Basically you make the success/failure the return value.

提交回复
热议问题