Tag: limits

C#中的调用堆栈限制

我想知道在我们得到堆栈溢出exception之前我们可以在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); } 我的问题是编译器如何决定抛出堆栈溢出exception是关于内存限制的? 一旦我把42995我得到stackoverflow但这个数字不是恒定所以这是如何工作的?