我对编程完全陌生,所以这可能是一个简单的答案的愚蠢问题。我的应用程序允许用户输入数字,选择他们使用的计量单位,选择他们要转换的计量单位并进行转换。
我在最后一行代码中有一个错误使其无法正常工作:'无法将类型'int'隐式转换为'string'。有人可以帮忙吗?
这是代码:
private void convertButton_Click(object sender, EventArgs e)
{
int fromDistance;
int toDistance;
fromDistance = int.Parse(distanceInput.Text);
string measureInput = fromList.Items[fromList.SelectedIndex].ToString();
string measureOutput = toList.Items[toList.SelectedIndex].ToString();
switch (measureInput)
{
case "Yards":
switch (measureOutput)
{
case "Yards":
toDistance = fromDistance;
break;
case "Feet":
toDistance = fromDistance * 3;
break;
case "Foot":
toDistance = fromDistance * 3 * 12;
break;
}
break;
case "Feet":
switch (measureOutput)
{
case "Feet":
toDistance = fromDistance;
break;
case "Yards":
toDistance = fromDistance / 3;
break;
case "Foot":
toDistance = fromDistance * 12;
break;
}
break;
case "Foot":
switch (measureOutput)
{
case "Foot":
toDistance = fromDistance;
break;
case "Feet":
toDistance = fromDistance / 12;
break;
case "Yards":
toDistance = fromDistance / (3 * 12);
break;
}
break;
}
distanceOutput.Text = toDistance;
}