【问题标题】:A namespace cannot directly contain members such as fields or methods.命名空间不能直接包含字段或方法等成员。
【发布时间】:2013-12-29 05:28:59
【问题描述】:

所以我得到了错误:

命名空间不能直接包含字段或方法等成员。

我双击它,它会把我带到case: 1002这一行

     #region Vip Seller
            case 1002:
               {
                    switch (npcRequest.OptionID)
                    {
                        case 0:
                            {
                                if (client.Entity.VIPLevel == 6)
                                {
                                    dialog.Text("your Are already VIP 6.");
                                    dialog.Option("I see.", 255);
                                    dialog.Avatar(116);
                                    dialog.Send();
                                    break;
                                }
                                dialog.Text("Hay i will upgrade your VIP for cps");
                                dialog.Option("[VIP 1] 20k cps.", 1);
                                dialog.Option("[VIP 2] 20k cps.", 2);
                                dialog.Option("[VIP 3] 15k cps.", 3);
                                dialog.Option("[VIP 4] 30k cps.", 4);
                                dialog.Option("[VIP 5] 15k cps.", 5);
                                dialog.Option("[VIP 6] 20k cps.", 6);
                                dialog.Option("Just passing by.", 255);
                                dialog.Avatar(116);
                                dialog.Send();
                                break;

                            }
                        case 1:
                            {
                                if (client.Entity.VIPLevel == 0 && client.Entity.VIPLevel < 1)
                                {
                                    if (client.Entity.ConquerPoints >= 20000)
                                    {
                                        client.Entity.ConquerPoints -= 20000;
                                        client.Entity.VIPLevel = 1;

                                    }

                                    else
                                    {
                                        dialog.Text("Please take 20k cps.");
                                        dialog.Option("I see.", 255);
                                        dialog.Avatar(116);
                                        dialog.Send();
                                    }

                                }
                                else
                                {
                                    dialog.Text("Sorry Can't upgrade any more.");
                                    dialog.Option("I see.", 255);
                                    dialog.Avatar(116);
                                    dialog.Send();
                                }

                                break;
                            }
                        case 2:
                            {
                                if (client.Entity.VIPLevel == 1)
                                {
                                    if (client.Entity.ConquerPoints >= 20000)
                                    {
                                        client.Entity.ConquerPoints -= 20000;
                                        client.Entity.VIPLevel = 2;
                                    }

                                    else
                                    {
                                        dialog.Text("Please take 20k cps.");
                                        dialog.Option("I see.", 255);
                                        dialog.Avatar(116);
                                        dialog.Send();
                                    }


                                }
                                else
                                {
                                    dialog.Text("Sorry Can't upgrade any more.");
                                    dialog.Option("I see.", 255);
                                    dialog.Avatar(116);
                                    dialog.Send();
                                }
                                break;
                            }
                        case 3:
                            {
                                if (client.Entity.VIPLevel == 2)
                                {
                                    if (client.Entity.ConquerPoints >= 15000)
                                    {
                                        client.Entity.ConquerPoints -= 15000;
                                        client.Entity.VIPLevel = 3;
                                    }

                                    else
                                    {
                                        dialog.Text("Please take 15k cps.");
                                        dialog.Option("I see.", 255);
                                        dialog.Avatar(116);
                                        dialog.Send();
                                    }


                                }
                                else
                                {
                                    dialog.Text("Sorry Can't upgrade any more.");
                                    dialog.Option("I see.", 255);
                                    dialog.Avatar(116);
                                    dialog.Send();
                                }
                                break;
                            }
                        case 4:
                            {
                                if (client.Entity.VIPLevel == 3)
                                {
                                    if (client.Entity.ConquerPoints >= 30000)
                                    {
                                        client.Entity.ConquerPoints -= 30000;
                                        client.Entity.VIPLevel = 4;
                                    }

                                    else
                                    {
                                        dialog.Text("Please take 150k cps.");
                                        dialog.Option("I see.", 255);
                                        dialog.Avatar(116);
                                        dialog.Send();
                                    }

                                }
                                else
                                {
                                    dialog.Text("Sorry Can't upgrade any more.");
                                    dialog.Option("I see.", 255);
                                    dialog.Avatar(116);
                                    dialog.Send();
                                }
                                break;
                            }
                        case 5:
                            {
                                if (client.Entity.VIPLevel == 4)
                                {
                                    if (client.Entity.ConquerPoints >= 15000)
                                    {
                                        client.Entity.ConquerPoints -= 15000;
                                        client.Entity.VIPLevel = 5;
                                    }

                                    else
                                    {
                                        dialog.Text("Please take 15k cps.");
                                        dialog.Option("I see.", 255);
                                        dialog.Avatar(116);
                                        dialog.Send();

                                    }

                                }
                                else
                                {
                                    dialog.Text("Sorry Can't upgrade any more.");
                                    dialog.Option("I see.", 255);
                                    dialog.Avatar(116);
                                    dialog.Send();
                                }
                                break;
                            }
                        case 6:
                            {
                                if (client.Entity.VIPLevel == 5)
                                {
                                    if (client.Entity.ConquerPoints >= 20000)
                                    {
                                        client.Entity.ConquerPoints -= 20000;
                                        client.Entity.VIPLevel = 6;
                                    }

                                    else
                                    {
                                        dialog.Text("Please take 20k cps.");
                                        dialog.Option("I see.", 255);
                                        dialog.Avatar(116);
                                        dialog.Send();

                                    }

                                }
                                else
                                {
                                    dialog.Text("Sorry Can't upgrade any more.");
                                    dialog.Option("I see.", 255);
                                    dialog.Avatar(116);
                                    dialog.Send();
                                }
                                break;
                            }
                    }
                    break;
                }
            #endregion

关于如何修复的任何建议?

【问题讨论】:

  • 您是否考虑过不直接将您的方法和字段(和语句)放在命名空间中?而是使用命名空间来存储一个类来存储一个方法来存储一个语句。我猜这是 C#?
  • 你的代码中有太多没有上下文的东西。例如,什么是“对话”、“客户端”和“npcRequest”?我们无法从我们坐的地方读懂你的想法或看到你的屏幕。

标签: c#


【解决方案1】:

好吧,case 语句应该在函数定义内,所以我猜你在某处缺少右括号,而这段代码似乎在命名空间内。 (顺便说一下,这里的缩进程度令人不安……)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多