2014-07-20 52 views
-1

我最近開始學習c#,沒有編程經驗,我已經創建了這個超級簡單的腳本來計算窗口安裝的材料成本,但是與String.Format(「{0:0。##}」Visual Studio給我一個錯誤 - '預期的方法名稱'。任何幫助都將是驚人的,因爲我無法在任何地方找到足夠的解決方案。在一類,並在Main()方法如果能夠以某種方式影響着它。String.Format方法名稱預期錯誤()

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(); 

回答

2

缺少一個逗號

String.Format("{0:0.##}" ,//<-- 
      ((glassArea * gCost) + (woodLength * wCost))); 
3

參數必須是逗號分隔,所以你就必須改變

decimal totalCost = String.Format("{0:0.##}"((glassArea * gCost) + (woodLength * wCost))); 

decimal totalCost = String.Format("{0:0.##}", ((glassArea * gCost) + (woodLength * wCost))); 

我沒有檢查其他錯誤。