Reputation: 217
How can I produce a StackOverflowException
with minimal lines of code?
Upvotes: 8
Views: 1386
Reputation: 20296
Not the shortest one but funny:)
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");
}
Upvotes: 18
Reputation: 52518
I always use this code (because it is harder to detect) :-(
private int _num;
public int Num {
get { return Num; }
set { _num = value; }
}
Upvotes: 4
Reputation: 61427
public int Method(int i)
{
return i + Method(i + 1);
}
I think this should work. In general, any recursion that doesn't terminate.
Upvotes: 2