切换参数中的表达式术语"大小写"无效

 安静的美男只 发布于 2023-02-13 12:34

我得到一个"错误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#区分大小写,因此您必须准确地键入关键字,更改Switchswitch它应该有效.

1 个回答
  • C#区分大小写,因此您必须准确地键入关键字,更改Switchswitch它应该有效.

    2023-02-13 12:35 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有