C# 奎因问题

发布于 2024-08-11 17:22:07 字数 786 浏览 12 评论 0原文

我试图了解这段自我复制代码的工作原理(在此处找到) ,但问题是我无法让它按原样运行:

class c {
    static void Main(){

        string s = "class c{{static void Main(){{string s={0}{10};System.Console.Write(s,(char)34,s);}}}}";

        System.Console.Write(s,(char)34,s); //<<-- exception on this line

    }
}

它在写入行上抛出异常:索引(基于零)必须大于或等于零且小于参数列表的大小。

有人可以提供帮助 - 特别是关于格式选项 {0}{10} 吗?

我得到它像这样工作(见下文),但它比原来的更长 - 我很好奇原来的如何可以按原样工作在第一:

class c {
    static void Main(){

        string s = "class c{{static void Main(){{string s={0}{1}{2};System.Console.Write(s,(char)34,s,(char)34);}}}}";

        System.Console.Write(s,(char)34,s,(char)34);
    }
}

I am trying to understand how this piece of self-replicating code works (found here), but the problem is I can't get it to run as-is:

class c {
    static void Main(){

        string s = "class c{{static void Main(){{string s={0}{10};System.Console.Write(s,(char)34,s);}}}}";

        System.Console.Write(s,(char)34,s); //<<-- exception on this line

    }
}

It's throwing an exception on writeline: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

Can someone help - in particular about the formatting option {0}{10}?

I got it working like this (see below) but it's longer than the original - I am curious how the original could have worked as-is in the 1st place:

class c {
    static void Main(){

        string s = "class c{{static void Main(){{string s={0}{1}{2};System.Console.Write(s,(char)34,s,(char)34);}}}}";

        System.Console.Write(s,(char)34,s,(char)34);
    }
}

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

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

发布评论

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

评论(3

微暖i 2024-08-18 17:22:07

我认为缺少一对大括号 - 而不是 {10},它应该是 {1}{0}

class c {
    static void Main(){

        string s = "class c{{static void Main(){{string s={0}{1}{0};System.Console.Write(s,(char)34,s);}}}}";

        System.Console.Write(s,(char)34,s); //<<-- exception on this line

    }
}

I think there is a pair of braces missing - instead of {10} it should read {1}{0}.

class c {
    static void Main(){

        string s = "class c{{static void Main(){{string s={0}{1}{0};System.Console.Write(s,(char)34,s);}}}}";

        System.Console.Write(s,(char)34,s); //<<-- exception on this line

    }
}
烟雨凡馨 2024-08-18 17:22:07

原版可以用吗?

s={0}{1}{0}

Could the original work with?

s={0}{1}{0}
樱&纷飞 2024-08-18 17:22:07

我相信原来的应该是这样的:

class c {
  static void Main() {
    string s = "class c{{static void Main(){{string s={0}{1}{0};System.Console.Write(s,(char)34,s);}}}}";
    System.Console.Write(s, (char)34, s);
  }
}

{0}{10} 应该更改为 {0}{1}{0}

格式字符串中的 {0} 用于在字符串前后放置引号。

I believe that the original was supposed to look like this:

class c {
  static void Main() {
    string s = "class c{{static void Main(){{string s={0}{1}{0};System.Console.Write(s,(char)34,s);}}}}";
    System.Console.Write(s, (char)34, s);
  }
}

I.e. the {0}{10} should just be changed to {0}{1}{0}.

The {0} in the format string is used to put the quotation marks before and after the string.

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