我不知道有多少电话,我们可以在C#之前,我们得到堆栈溢出异常在C#中调用堆栈限制
堆栈执行,所以我决定写如下代码
static void Method2(int Calls)
{
if(!Calls.Equals(0))
Method1(--Calls);//if more calls remain call method1 and reduce counter
}
static void Method1(int Calls)
{
if (!Calls.Equals(0))//if more calls remain call method2 and reduce counter
Method2(--Calls);
}
static void Main(string[] args)
{
var Calls= 42994;//number of calls(stack overflow appears for large number)
Method1(Calls);
}
我的问题是如何编译决定抛出堆栈溢出异常 这是关于内存限制吗? 一旦我把42995我得到了stackoverflow但这个数字不是恒定的,所以这是如何工作的?
从技术上讲,编译器不会抛出这个异常,运行时会这样做。 – BradleyDotNET
好吧......这是怎么发生的?@BradleyDotNET –
堆栈中有恒定的空间量,而不是一个固定数量的函数调用。 – Gabe