请注意,重试没有退出条件,如果答案始终不是“随便”,则递归不会结束,我们只会以该站点的“同名”结束。
public bool fun(string name)
{
     bool retry = Properties.Resources.retry == "true";
      string result = Get(name);
      if (result == "whatever")
      {
           return true;
       }
       else if (retry)
       {
            Console.WriteLine("Retrying");
            return fun(name);
        }
        return false;
}
更新
与其将重试作为布尔值,我更愿意将其作为整数。这控制了退出条件。
    private bool fun(string name, int retryCount)
    {
        string result = Get(name);
        if (result == "whatever")
        {
            return true;
        }
        if (retryCount > 0)
        {
            return fun(name, retryCount - 1);
        }
        return false;
    }
    public static bool fun(string name)
    {
        bool retry = Properties.Resources.retry == "true";
        int retryCount = Int32.Parse(Properties.Resources.retryCount);
        return fun(name, retryCount);                       
    }