C# 奎因问题
我试图了解这段自我复制代码的工作原理(在此处找到) ,但问题是我无法让它按原样运行:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为缺少一对大括号 - 而不是
{10}
,它应该是{1}{0}
。I think there is a pair of braces missing - instead of
{10}
it should read{1}{0}
.原版可以用吗?
Could the original work with?
我相信原来的应该是这样的:
即
{0}{10}
应该更改为{0}{1}{0}
。格式字符串中的
{0}
用于在字符串前后放置引号。I believe that the original was supposed to look like this:
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.