在转换为摄氏度或华氏度之间实现用户选择的最佳方式是什么


namespace TemperatureConverter
{
class Program
{
public static float celsius, fahrenheit;
public static void Main(string[] args)
{
Console.Write("Are you converting Celsius or Fahrenheit?: ");
celsius = Convert.ToSingle(Console.ReadLine());
fahrenheit = (celsius * 9 / 5) + 32;
Console.WriteLine("The temperature in fahrenheit is " + fahrenheit);
}
static void ToFahrenheit()
{
}
static void ToCelsius()
{
}
}

}

我正在尝试实现一种方法,用户可以选择在编译后转换为摄氏度或华氏度。

Console.WriteLine("Do you want to convert to (F)ahrenheit or to (C)elsius? ");
ConsoleKeyInfo key;
do
{
key = Console.ReadKey();
if (key.Key == ConsoleKey.F)
{
return ToFahrenheit(/* */);
}
if (key.Key == ConsoleKey.C)
{
return ToCeclsius(/* */);
}
Console.WriteLine("Please press F or C to make your selection");
} while (true);

最新更新