我想知道,总和来自哪里?我知道递归是什么,但我无法弄清楚如何int i获得总和.我已经读过关于堆栈......但我仍然不明白.请帮忙:)这里是代码:
static void Main(string[] args)
{
int i = RecursiveMethod(1,3);
//Console.ReadLine();
}
static int RecursiveMethod(int a, int b)
{
Console.WriteLine(a);
if (a == b)
{
return a;
}
else
{
return a + RecursiveMethod(a + 1, b);
}
}
Run Code Online (Sandbox Code Playgroud)