无法步入递归函数断点VS2013

Unable to step-in to Recursive function breakpoint VS2013

我试图将带有 for 循环的方法转换为递归,作为编码 Kata 实践的一部分(尝试用递归方法解决问题)。逻辑上没什么,但

这是方法定义:

    // Original method with for loop
    public IEnumerable<Tuple<int, int>> GetElementWithLargestDeltaOnTimeline(int[] a)
    {
        int runningLindex = 0;
        int currLValue = a[0];
        int runningHindex = 1;
        int currHvalue = a[1];
        int currDelta = 0;

        for (int i = 1; i < a.Length - 1; i++)
        {
            if (a[i] < currLValue)
            {
                currLValue = a[i];
                runningLindex = i;
            }

            for (int j = runningLindex + 1; j < a.Length; j++)
            {
                if ((a[j] - currLValue) > currDelta)
                {
                    currDelta = a[j] - currLValue;
                    runningHindex = j;
                    currHvalue = a[j];
                }
            }
        }

        yield return new Tuple<int, int>(currLValue, runningLindex);
        yield return new Tuple<int, int>(currHvalue, runningHindex); 
    }

递归 -

    // Trying above method to convert to recursive, 
    // Note - It may not be correct *shy* but the problem is why it's not doing anything(not step through/logging)
    public IEnumerable<Tuple<int, int>> GetElementWithLargestDeltaOnTimelineRec
        (int[] a, int i, int j, int runningLindex, int currLValue, int runningHindex, int currHvalue, int currDelta)
    {
        Console.WriteLine("Iteration i-{0}: j-{1} runningLindex-{2} currLValue-{3} runningHindex-{4} currHvalue-{5} currDelta-{6}"
                                   , i, j, runningLindex, currLValue, runningHindex, currHvalue, currDelta);
        if (i < a.Length)
        {
            if (a[i] < currLValue)
            {
                currLValue = a[i];
                runningLindex = i;
            }

            if (j < a.Length)
            {
                if ((a[j] - currLValue) > currDelta)
                {
                    currDelta = a[j] - currLValue;
                    runningHindex = j;
                    currHvalue = a[j];
                }

                GetElementWithLargestDeltaOnTimelineRec(a, i, j++, runningLindex, currLValue, runningHindex, currHvalue, currDelta);
            }
        }
        else
        {
            yield return new Tuple<int, int>(currLValue, runningLindex);
            yield return new Tuple<int, int>(currHvalue, runningHindex);
        }

        GetElementWithLargestDeltaOnTimelineRec(a, i++, runningLindex + 1, runningLindex, currLValue, runningHindex, currHvalue, currDelta);
        yield break;
    }

主要 -

public class Program
{
    public static void Main()
    {
        var a = new[] { 10, 9, 3, 6, 7, 8, 15, 10, 6 };
        var val = new StockManager();
        var result = val.GetElementWithLargestDeltaOnTimelineRec(a, 0, 0, 0, a[0], 1, a[1], 0);
    }
}

问题 -

附加信息 - .Net 4.5,Visual studio 2013

我也在不同的机器上尝试了 运行 这段代码(只是为了验证我的 VS 实例是否有问题)。

return IEnumerable 方法有一个小技巧。你应该列举它们!

与其在自身内部调用 GetElementWithLargestDeltaOnTimelineRec,不如枚举它并生成 return 它的元素或存储结果以备后用。 IEnumerable在枚举之前什么都不做。

foreach (var e in GetElementWithLargestDeltaOnTimelineRec(...))
    yield return e;

var innerResult = GetElementWithLargestDeltaOnTimelineRec(...);

并以某种方式使用 innerResult 导致它被枚举。