我试图从我在不同类中编写的方法获取输出,以将值返回到 writeline 语句的中间。错误“运算符'+'不能应用于'字符串'和'方法组'类型的操作数”正在停止运行任何东西,但我似乎无法找到解决错误的方法。这可能是我错过的一件真正简单的事情,但我对编程仍然很陌生,所以我可能错过了一些明显的东西。
public void EatFruits()
{
double dblpercent;
this.MakeFruits();
Console.WriteLine("You have an Apple and a Banana in your fruit garden.");
Console.WriteLine("What Percent of the Apple would you like to eat?");
dblpercent = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("What Percent of the Banana would you like to eat?");
dblpercent = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("You have " + (apple.Eat) + "% of your apple and " + (banana.Eat) + "% of your banana left.");
}
另一个类中 Eat 方法的代码是:
public double Eat(double dblpercent)
{
return (PercentFruitLeft-dblpercent);
}
PercentFruitLeft 很早就设置为 100,然后根据用户输入的想要吃多少来减少。