【发布时间】:2011-05-27 05:19:31
【问题描述】:
如何用最少的代码行生成StackOverflowException?
【问题讨论】:
标签: c# .net stack-overflow
如何用最少的代码行生成StackOverflowException?
【问题讨论】:
标签: c# .net stack-overflow
throw new StackOverflowException();
作弊,我知道... :)
【讨论】:
try { throw new StackOverflowException(); } catch (StackOverflowException ex) { Console.WriteLine("Yes you can."); }(抱歉,我知道它已经过时了:)
像这样:
A() { new A(); }
【讨论】:
void 返回吗?)
new。
int A() { return A(); }。
伪代码
func(): call func()
【讨论】:
public int Method(int i)
{
return i + Method(i + 1);
}
我认为这应该可行。一般来说,任何不会终止的递归。
【讨论】:
public static void Main()
{
Main();
}
【讨论】:
我总是使用这个代码(因为它更难检测):-(
private int _num;
public int Num {
get { return Num; }
set { _num = value; }
}
【讨论】:
num(不带下划线前缀)就更好了。 ;)
不是最短的,但很有趣:)
public static bool IsNotEmpty(string value)
{
return !IsEmpty(value);
}
public static bool IsEmpty(string value)
{
return !IsNotEmpty(value);
}
public static void Main()
{
bool empty = IsEmpty("Hello World");
}
【讨论】:
运行这段代码(递归):
f () {
f();
}
【讨论】: