我正在做一个用开尔文,摄氏和华氏温度转换温度的简单程序,但是在用开尔文做任何事情时我都会遇到这个错误:
Cannon implicitly convert type 'double' to 'float'
Run Code Online (Sandbox Code Playgroud)
发生错误的行:
public static float FahrenheitToKelvin(float fahrenheit)
{
return ((fahrenheit - 32) * 5) / 9 + 273.15;
}
Run Code Online (Sandbox Code Playgroud)
按钮点击:
private void button1_Click(object sender, EventArgs e)
{
var input = float.Parse(textBox1.Text);
float FahrenResult = FahrenheitToCelsius(input);
textBox2.Text = FahrenResult.ToString();
float KelvinResult = FahrenheitToKelvin(input);
textBox3.Text = KelvinResult.ToString();
}
Run Code Online (Sandbox Code Playgroud)
我试图做的测试方法:
[TestMethod]
public void fahrenheitToKelvinBoiling()
{
float fahrenheit = 212F;
float expected = 373.15F; // TODO: Initialize to an appropriate value
float actual;
actual = Form1.FahrenheitToKelvin(fahrenheit);
Assert.AreEqual(Math.Round(expected, …Run Code Online (Sandbox Code Playgroud)