我得到一个"错误1当前上下文中不存在名称'Switch'"和我的交换机语句中的"无效表达式术语'case'"错误.我的问题是这些错误意味着什么?这是开关
private void buttonRead_Click(object sender, EventArgs e) { int Selected = listColours.SelectedIndex; Colours newColour; Switch(Selected) { case 0: newColour = Colours.red; MessageBox.Show(newColour.ToString(), "Output", MessageBoxButtons.OK, MessageBoxIcon.Information); break; case 1: newColour = Colours.orange; MessageBox.Show(newColour.ToString(), "Output", MessageBoxButtons.OK, MessageBoxIcon.Information); break; case 2: newColour = Colours.yellow; MessageBox.Show(newColour.ToString(), "Output", MessageBoxButtons.OK, MessageBoxIcon.Information); break; case 3: newColour = Colours.green; MessageBox.Show(newColour.ToString(), "Output", MessageBoxButtons.OK, MessageBoxIcon.Information); break; case 4: newColour = Colours.blue; MessageBox.Show(newColour.ToString(), "Output", MessageBoxButtons.OK, MessageBoxIcon.Information); break; case 5: newColour = Colours.purple; MessageBox.Show(newColour.ToString(), "Output", MessageBoxButtons.OK, MessageBoxIcon.Information); break; }
King King.. 8
C#
区分大小写,因此您必须准确地键入关键字,更改Switch
为switch
它应该有效.
C#
区分大小写,因此您必须准确地键入关键字,更改Switch
为switch
它应该有效.