C# String.Format()上的方法名称应为错误
我最近开始学习c语言,之前没有编程经验,我创建了这个超级简单的脚本,用于计算窗口安装的材料成本,但是使用了字符串。Format{0:0.}Visual Studio给了我一个错误—“预期的方法名称”。任何帮助都会令人惊讶,因为我在任何地方都找不到足够具体的解决方案。请注意,它都包含在一个类和Main方法中,如果这可能会影响它的话C# String.Format()上的方法名称应为错误,c#,C#,我最近开始学习c语言,之前没有编程经验,我创建了这个超级简单的脚本,用于计算窗口安装的材料成本,但是使用了字符串。Format{0:0.}Visual Studio给了我一个错误—“预期的方法名称”。任何帮助都会令人惊讶,因为我在任何地方都找不到足够具体的解决方案。请注意,它都包含在一个类和Main方法中,如果这可能会影响它的话 Console.Write("How wide is the window in metres: "); decimal frameWidth = Co
Console.Write("How wide is the window in metres: ");
decimal frameWidth = Convert.ToDecimal(Console.ReadLine());
Console.Write("How tall is the window in metres? ");
decimal frameHeight = Convert.ToDecimal(Console.ReadLine());
decimal glassArea = (frameWidth * frameHeight) ;
decimal woodLength = (frameWidth * 2) + (frameHeight * 2);
Console.WriteLine("You will need " + glassArea + "m squared of glass and " + woodLength + "m of wood.");
Console.Write("What is the current cost of glass per square metre? £");
decimal gCost = Convert.ToDecimal(Console.ReadLine());
Console.Write("What is the current cost of wood per metre? £");
decimal wCost = Convert.ToDecimal(Console.ReadLine());
decimal totalCost = String.Format("{0:0.##}"((glassArea * gCost) + (woodLength * wCost)));
Console.WriteLine("The total cost for the required materials is £" + totalCost );
Console.WriteLine("Press any key to exit...");
Console.ReadLine();
参数需要用逗号分隔,因此必须进行更改
decimal totalCost = String.Format("{0:0.##}"((glassArea * gCost) + (woodLength * wCost)));
进入
我没有检查其他错误。缺少逗号
String.Format("{0:0.##}" ,//<--
((glassArea * gCost) + (woodLength * wCost)));
String.Format("{0:0.##}" ,//<--
((glassArea * gCost) + (woodLength * wCost)));