简体   繁体   中英

Error Message: Operator '+' cannot be applied to operands of type 'string' and 'method group'

When working on a class Project in Microsoft Visual Studio, I ran across the following error:
Operator '+' cannot be applied to operands of type 'string' and 'method group'

These are the relevant pieces of code:

 public double CalculateTotalFuelCost()
    {
        double CalculateTotalFuelCost = gallonsConsumed * fuelCostPerGallon;
        return CalculateTotalFuelCost;
    }

and

   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;
    }

The error covers this small snippet of the above code.

+ "\nTotal Fuel Cost for this Trip: $" + CalculateTotalFuelCost

Everything else shows no errors. I have no idea what I am doing wrong. Thank you for any help and advice that can be offered.

It's a function you forgot the ()

CalculateTotalFuelCost()

Do the same for all the other functions you're trying to call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM