Cannot put "default" to switch block

I have looked at the similar questions and answers, but i still cannot see the problem in my code. I have a switch statement and here it is:

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:
                {

                }
        }

The problem is, the default block produces an error saying that

Control cannot fall through from one case label ('default:') to another

Can anyone help me with this?

Thanks


You should add break; for the default case as well.


Each switch case is required to have transfer control [ break , return , throw ] as it does not allow fall through .

add break (asper your code) for your default case too as beow:

default:
        {

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

上一篇: 切换为java 1.6的字符串类型

下一篇: 无法将“默认”置于切换块