Input area ({) per line in a console application

I am trying to write a code generator using a C # console application. Now, when I print this, I get an error message:

    Console.WriteLine("sphere {{0}{1} {2} texture{Gold_Metal}}", 
    pre, i.ToString(), sprad.ToString());

It says "input in the wrong format." I checked that all the variables were strings, and they are. When i tried

    Console.WriteLine("sphere {0}{1} {2} textureGold_Metal", 
    pre, i.ToString(), sprad.ToString());

It worked perfectly. Is there any way to fix this?

+5
source share
3 answers

Assuming you want the literal to {be inserted into the stream, you need to avoid yours {with another combination:

Console.WriteLine("sphere {{{0}{1} {2} ...
                          ^^
                          ||-- see here.

, " MSDN" . {{ {, }} }.

, , , :

Console.WriteLine("sphere {{{0}{1} {2} texture{{Gold_Metal}}}}", 
    pre, i.ToString(), sprad.ToString());

- :

sphere {<Arg0><Arg1> <Arg2> texture{Gold_Metal}}
+4

{{ "" . Writeln {{0} 'literal {', 0}, .

+2

, , , . , , . ToString(); , . , pre, sprad i

 Console.WriteLine(string.Format("sphere {0}{1} {2} textureGold_Metal", 
    pre, i.ToString(), sprad.ToString()));
0

All Articles