在Microsoft Visual Studio中处理类Project时,我遇到了以下错误:
运营商' +'不能应用于' string'类型的操作数和'方法组'
这些是相关的代码:
public double CalculateTotalFuelCost()
{
double CalculateTotalFuelCost = gallonsConsumed * fuelCostPerGallon;
return CalculateTotalFuelCost;
}
和
public override string ToString()
{
return "Destination: " + destination + "\nTotal Miles: " + distanceTraveled + "\nFuel Consumed: " + gallonsConsumed + " gallons" + "\nFuel Cost Per Gallon: $" +
fuelCostPerGallon + "\nTotal Fuel Cost for this Trip: $" +
CalculateTotalFuelCost + "\nMPG: " + CalculateMilesPerGallon +
"\n Fuel Cost Per Mile: $" + CalculateCostPerMile;
}
错误涵盖了上述代码的这个小片段。
+ "\nTotal Fuel Cost for this Trip: $" + CalculateTotalFuelCost
其他一切都没有显示任何错误。 我不知道我做错了什么。感谢您提供任何帮助和建议。
答案 0 :(得分:2)
这是您忘记()
CalculateTotalFuelCost()
对您尝试呼叫的所有其他功能执行相同的操作。