如何用几行代码产生StackOverflowException?

发布于 2024-10-08 07:10:02 字数 55 浏览 5 评论 0原文

如何用最少的代码行生成 StackOverflowException

How can I produce a StackOverflowException with minimal lines of code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

恍梦境° 2024-10-15 07:10:02
throw new StackOverflowException();

作弊,我知道...:)

throw new StackOverflowException();

Cheating, I know... :)

神回复 2024-10-15 07:10:02

像这样:

A() { new A(); }

Like this:

A() { new A(); }
好菇凉咱不稀罕他 2024-10-15 07:10:02

不是最短的,但很有趣:)

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

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");
}
岁月苍老的讽刺 2024-10-15 07:10:02
public static void Main()
{
  Main();
}
public static void Main()
{
  Main();
}
风渺 2024-10-15 07:10:02

我总是使用这个代码(因为它更难检测):-(

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

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

private int _num;
public int Num {
   get { return Num; }
   set { _num = value; }
}
腻橙味 2024-10-15 07:10:02

在伪代码中

func(): call func()

in pseudocode

func(): call func()
往事随风而去 2024-10-15 07:10:02
public int Method(int i)
{
  return i + Method(i + 1);
}

我认为这应该有效。一般来说,任何不终止的递归。

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

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

秋叶绚丽 2024-10-15 07:10:02

运行此代码(递归):

f () {
       f();
    }

Run this code (recursion):

f () {
       f();
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文