我发现了 这个问题关于哪些语言优化了尾部递归。为什么 C # 不优化尾部递归,只要有可能?
For a concrete case, why isn't this method optimized into a loop (VisualStudio2008 32-bit, if that matters)?:
private static void Foo(int i)
{
if (i == 1000000)
return;
if (i % 100 == 0)
Console.WriteLine(i);
Foo(i+1);
}