开发者

How to produce a StackOverflowException with a few lines of code?

How can I produce a StackOverflowException with minimal lines of co开发者_JAVA技巧de?


throw new StackOverflowException();

Cheating, I know... :)


Like this:

A() { new A(); }


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");
}


public static void Main()
{
  Main();
}


I always use this code (because it is harder to detect) :-(

private int _num;
public int Num {
   get { return Num; }
   set { _num = value; }
}


in pseudocode

func(): call func()


public int Method(int i)
{
  return i + Method(i + 1);
}

I think this should work. In general, any recursion that doesn't terminate.


Run this code (recursion):

f () {
       f();
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜