几秒钟后,以下程序输出
进程因 StackOverflowException 而终止
而不是我的消息。为什么?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
namespace maximumVariable
{
class Program
{
public static BigInteger Factorial(int num)
{
try
{
return (num > 1) ? num*Factorial(num - 1) : (1);
}
catch
{
throw;
}
}
static void Main(string[] args)
{
BigInteger kingKong=0;
int facParameter=0;
try
{
while (true)
{
kingKong = Factorial(facParameter);
facParameter++;
}
}
catch
{
Console.WriteLine("The maximum value " + kingKong.ToString()+"has been achieved after "+facParameter.ToString()+" iterations");
}
}
}
}