通过下面递归的例子,做递归时先思考一下。
static void Main(string[] args)
{
for (long count = 0; count <= 10; count++)
{
Console.WriteLine("{0}! = {1}", count, Factorial(count));
}
}
private static long Factorial(long number)
{
if (number <= 1)
return 1;
else
return number * Factorial(number - 1);
}
显示结果如下: