私はプログラミングにまったく慣れていないので、これはおそらく単純な答えのばかげた質問です。私のアプリケーションでは、ユーザーは数値を入力し、使用する測定単位を選択し、変換する測定単位を選択して変換できます。
コードの最後の行に、動作を妨げているエラーが 1 つあります。誰か助けてくれませんか?
コードは次のとおりです。
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;
}