简体   繁体   中英

Why method call (i.e. ToString) executed before divisision ( / )?

I have a method and want to convert the result to string with a specific format. Here is my code:

private double MinimunWeight()
{
   return 18.5 / Math.Sqrt(Evaluation.Height).ToString("0.0");
}

It fails to compile with:

Operator '/' cannot be applied to operands of type 'double' and 'string'

What's the correct way to achieve that?

You mean this?

private string MinimunWeight()
{
    return (18.5 / Math.Sqrt(Evaluation.Height)).ToString("0.0");
}

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