Writing scope ({) into string in console app

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?


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.

Change what you have to write this and see if it works.. also make sure that you are converting the variable types where you have .ToString(); would need to know what the actual declared types are.. paste the code in where you have declared pre, sprad, and i

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

Need Your Help

MPMoviePlayerController audio/video out of sync

objective-c audio mpmovieplayercontroller sync

In my iPad App, I create an MPMoviePlayerController that plays an MP4 off of a website. In the MP4 there are people talking. In the App, I have noticed that the audio and video are out of sync by...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.