我在此代码上有错误。 它说“并非所有代码路径都返回值”,请帮助我解决此问题。 谢谢

public static double subtotal;

public static void Main(String[] args)
{
  subtotal = 15.00;
  Console.WriteLine($"Subtotal : {subtotal}");

  double total = subtotal + CalculateTax(7);
  Console.WriteLine($"Total : {total}");
}

public static double CalculateTax(double taxRate)
{
  double tax = subtotal * taxRate;
  Console.WriteLine($"Tax: {tax}");
}

===============>>#1 票数:2

尝试这个

public static double CalculateTax(double taxRate)
{
    double tax = subtotal * taxRate;
    Console.WriteLine($"Tax: {tax}");
    return tax;
}

  ask by Lena translate from so

未解决问题?本站智能推荐: