I am trying to write a code generator using a c# console application. Now when I type this, I receive an error:
Console.WriteLine("sphere {{0}{1} {2} texture{Gold_Metal}}",
pre, i.ToString(), sprad.ToString());
It says "input in wrong format" I have 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 fine. Is there a way to fix this?
Console. WriteLine("This is C#"); In this code line, we print the "This is C#" string to the console. To print a message to the console, we use the WriteLine method of the Console class.
Writing in Console App In C# you can write or print to console using Console. WriteLine() or Console. Write(), basically both methods are used to print output of console. Only difference between Console.
The ReadLine method reads a line from the standard input stream. (For the definition of a line, see the paragraph after the following list.) This means that: If the standard input device is the keyboard, the ReadLine method blocks until the user presses the Enter key.
The only difference between the Read() and ReadLine() is that Console. Read is used to read only single character from the standard output device, while Console. ReadLine is used to read a line or string from the standard output device. Program 1: Example of Console.
Assuming you want a literal {
inserted into the stream, you need to escape a your {
with yet another brace thus:
Console.WriteLine("sphere {{{0}{1} {2} ...
^^
||-- see here.
Similarly for the end-brace, this is detailed in the MSDN string formatting FAQ here. The sequence {{
becomes {
and }}
becomes }
.
From what I understand your intent to be, the full statement in your specific case would be:
Console.WriteLine("sphere {{{0}{1} {2} texture{{Gold_Metal}}}}",
pre, i.ToString(), sprad.ToString());
which should give you something like:
sphere {<Arg0><Arg1> <Arg2> texture{Gold_Metal}}
You need to use {{
to "escape" the curly brace. Writeln
interprets {{0}
as 'literal {' followed by 0}
, resulting in the wrong format error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With