Problem with C # Cine

I am trying to understand how this piece of self-reproducing code works (found here ), but the problem is that I cannot 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 throws an exception in the scenario: The index (based on zero) must be greater than or equal to zero and smaller than the size of the argument list.

Can anyone help - in particular regarding the formatting option {0} {10}?

I worked like this (see below), but it is longer than the original - I am curious how the original could work as in 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);
    }
}
+3
source share
3 answers

, - {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

    }
}
+8

?

s={0}{1}{0}
+4

I believe the original should have looked 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);
  }
}

those. {0}{10}should just change to {0}{1}{0}.

{0} in the format string is used to place quotes before and after the string.

+3
source

Source: https://habr.com/ru/post/1723339/


All Articles