我正在做一本書中的例子: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