我有以下一段代码,但是当我输入“12”时,我仍然得到“你是个老人”。9 - 15 不是 9 到 15 的数字吗?我如何在一种情况下处理多个值?
int age = Convert.ToInt32(txtBoxAge.Text);
switch (age)
{
case 1 - 8:
MessageBox.Show("You are only " + age + " years old\n You must be kidding right.\nPlease fill in your *real* age.");
break;
case 9 - 15:
MessageBox.Show("You are only " + age + " years old\n That's too young!");
break;
case 16-100:
MessageBox.Show("You are " + age + " years old\n Perfect.");
break;
default:
MessageBox.Show("You an old person.");
break;
}