namespace ConsoleApplication1
{
class class1
{
protected internal string inf1()
{
Console.WriteLine("\n......inf1() \n");
return inf1();
}
}
class class2 :class1
{
static void Main(string[] args)
{
class1 c1 = new class1();
class2 c2 = new class2();
Console.WriteLine(c1.inf1());
Console.WriteLine(c2.inf1());
Console.ReadKey();
}
}
获取无限循环问题。进程因StackOverflowException
而终止?获取无限循环问题。进程由于StackOverflowException而终止?
如何防止代码无限循环?
是的,inf1被递归调用,因此导致无限循环,所以堆栈溢出是预期的行为。你的问题是什么,或者你不明白什么? – 2014-09-24 12:12:58
你的代码显然有无限递归,方法inf1总是执行自己,你期望发生什么? – 2014-09-24 12:13:24
这是什么意思?你想要在父类中调用一个方法吗? – Luaan 2014-09-24 12:17:17