无法将“默认”置于切换块

我已经看过类似的问题和答案,但我仍然无法在代码中看到问题。 我有一个switch语句,在这里是:

switch (header)
        {
            case Headers.Queue:
                {
                    int id = pr.ReadInt32();
                    string fileName = pr.ReadString();
                    long length = pr.ReadInt64();

                    TransferQueue queue = TransferQueue.CreateDownloadQueue(this, id, Path.Combine(downloadDirectory,
                        Path.GetFileName(fileName)), length);

                    _transfers.Add(id, queue);

                    if (Queued != null)
                    {
                        Queued(this, queue);
                    }
                }
                break;
            case Headers.Start:
                {
                    int id = pr.ReadInt32();

                    if (_transfers.ContainsKey(id))
                    {
                        _transfers[id].Start();
                    }
                }
                break;
            case Headers.Chunk:
                {
                    int id = pr.ReadInt32();
                    long index = pr.ReadInt64();
                    int size = pr.ReadInt32();
                    byte[] buffer = pr.ReadBytes(size);

                    TransferQueue queue = _transfers[id];

                    queue.Write(buffer, index);

                    queue.Progress = (int)((queue.Transferred * 100) / queue.Length);
                    if (queue.LastProgress < queue.Progress)
                    {
                        queue.LastProgress = queue.Progress;

                        if (ProgressChanged != null)
                        {
                            ProgressChanged(this, queue);
                        }

                        if (queue.Progress == 100)
                        {
                            queue.Close();

                            if (Complete != null)
                            {
                                Complete(this, queue);
                            }
                        }
                    }
                }
                break;
            default:
                {

                }
        }

问题是,默认块产生一个错误说

控制不能从一个案例标签('default:')到另一个案例标签

谁能帮我这个?

谢谢


你应该补充break; 对于default情况也是如此。


每个switch盒都需要有transfer control [ breakreturnthrow ],因为它不允许fall through

在你的default情况下添加break (如代码):beow:

default:
        {

        }
break;
链接地址: http://www.djcxy.com/p/84501.html

上一篇: Cannot put "default" to switch block

下一篇: What is the better pratice: duplicate code or use goto statement?