C#奎因问题 [英] C# Quine Problem
问题描述
我想了解这片自我复制的代码工作(发现这里一>),但问题是我不能让它跑的按原样
C类{
静态无效的主要(){
字符串s =C类{{静态无效的主要(){{字符串s = {0} {10}; System.Console .WRITE(S,(炭)34,S);}}}};
System.Console.Write(S,(焦)34,S); //<< - 在这条线
}
}
$ B例外$ b
它投掷的WriteLine异常:索引(从零开始)必须小于参数列表的大小大于或等于0且小于
可有人能帮助? - 尤其是关于格式化选项{0} {10}
我得到它的工作是这样的(见下文),但它比原来长 - 我很好奇,原来如何能够担任-在第一名:
C类{
静态无效的主要(){
字符串s =C类{{静态无效的主要(){{字符串s = {0} {1} {2}; System.Console。写(S,(焦)34,S(炭)34);}}}};
System.Console.Write(S,(焦)34,S(炭)34);
}
}
我觉得有一对大括号缺少的 - 而不是 {10}
应该读 {1} {0}
。
C类{
静态无效的主要(){
字符串s =级13 C {{静态无效的主要(){{字符串s = {0} {1} {0}; System.Console.Write(S,(焦)34,S);}}}};
System.Console.Write(S,(焦)34,S); //<< - 在这条线
}
}
例外
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);
}
}
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
}
}
这篇关于C#奎因问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!