我正在做一本书中的例子:Herbert Schildt的完整参考C#3.0。这是关于使用参数在Console.WriteLine中写入的。这里是例子: 我试过,但我得到了一个错误:参数错误c#
Project1.exe has encountered a problem and needs to be close. We are sorry for the inconvenience. Please tell Microsoft about this problem. Send Error Report or Don't Send. And if I click, I get another error in the command prompt. "Unhandled Exception: System.Format.Exception input string was not in a correct format. at System.Text.StringBuilder.AppendFormatError() at System.Text.StringBuilder.AppendFormat(IFormatProvider provider,String Format, Object[]args) at System.IO.TextWriter.WriteLine(String format, Object arg0) at System.IO.TextWriter.SyncTextWriter.WriteLine(String format, Object arg0) At Example2.Main() in D:\myPath
我不知道,如果这本书有一些错误,或者是我的代码? 我将不胜感激您的帮助。由于
One of the easiest ways to specify a format is to describe a template that WriteLine() will use. To do this, show an example of the format that you want, using #s to mark the digit positions. You can also specify the decimal point and commas. For example, here is a better way to display 10 divided by 3:
Console.WriteLine("Here is 10/3: {0:#.##}", 10.0/3.0);
The output from this statement is shown here: Here is 10/3: 3.33
顺便说一句,这是我的代码如下所示:
static void Main()
{
Console.WriteLine("Here is 10/3: {0:#.##)", 10);
}
嗨Lasse V. Karlsen,谢谢我现在明白了。是的,它是大括号。这很简单。谢谢 – tintincutes 2009-05-26 20:15:54