class conv
{
public double input;
public double value;
public double ctf()
{
value = (9.0 / 5.0) * input + 32;
return value;
}
public double ftc()
{
value = (5.0 / 9.0) * (input - 32);
return value;
}
}
//需要两个类。例如,当我输入 100 并尝试从摄氏度转换为华氏度时,答案是 32,而从华氏度到摄氏度的转换为 -17.7777777!
public partial class Form1 : Form
{
double input = double.Parse(textBox1.Text);
try
{
conv cf = new conv();
if (comboBox1.Text == "celsius to fahrenheit")
{
cf.ctf();
label3.Text = cf.value.ToString();
}
else if (comboBox1.Text == "fahrenheit to celsius")
{
cf.ftc();
label3.Text = cf.value.ToString();
}