递归函数的奇怪行为

Pie*_*rto 0 c# recursion flow

我有这个代码:

    public void myFunction(String label, String type, string command, int attempts = 0)
    {
        try
        {
            Utility.Logger("myFunction attempt " + attempts.ToSafeString() + " label " + label + " type " + type, command);
            ...stuff...
        }
        catch (Exception e)
        {
            if (attempts < 10)
                return myFunction(label, type, command, attempts++);
            else
                return null;
        }
    }
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我在catch分支中有一个递归调用,在这里我设置一个参数一个counter = counter + 1.

奇怪的是我在日志中总是尝试= 0.为什么?我错过了什么?

C.E*_*uis 7

attempts++attempts 之后递增,++attempts在递归之前递增.