我想將變量temperature和windSpeed發送到ComputeWindChill方法來查找windchill。然後將windchill返回到Main方法以顯示溫度,風速和包括風寒的溫度。如何將變量從Main發送到另一個方法,然後將值返回給Main方法?
public class Program
{
public static void Main(string[] args)
{
Random rnd = new Random();
int temperature = rnd.Next(0,50);
int windSpeed = rnd.Next(4,30);
Console.Write("Temperature: {0}", temperature);
Console.WriteLine();
Console.Write("Wind Speed: {0}", windSpeed);
Console.WriteLine();
Console.Write("Temperature (including windchill): {0}", ComputeWindChill.windChill);
ComputeWindChill(temperature);
ComputeWindChill(windSpeed);
} // end Main
public double ComputeWindChill(int temperature, int windSpeed, double windChill)
{
windChill = 35.74 + 0.6215 * temperature - 35.75 * Math.Pow(windSpeed,0.16) +
0.4275 * temperature * Math.Pow(windSpeed,0.16);
return windChill;
}
} // end class
什麼是你的代碼錯誤後,又回到Windchill的價值?錯誤?意外的結果? –
'ComputeWindChill'會返回一個值,但不會捕獲它。它也需要3個參數(但似乎應該只需要2個,因爲一個是結果)代碼只能通過1 – Plutonix