错误类型或命名空间定义,或Command:joke中预期的文件结尾

时间:2014-11-29 21:31:21

标签: c#

我的代码收到此错误:错误类型或命名空间定义,或Command:joke中预期的文件结尾。

我想从列表中随机选择一些东西。这是通过Skype僵尸程序运行的,但每个命令都是不同的脚本。 这是代码:

using System;
using System.Collections.Generic;
using System.Text;
using Skyper;
using SKYPE4COMLib;
using System.Net;

namespace Skyper.plugins
{

    public static class Help
    {

        public static string Description
        {
            get 
            {
                return "Random Object Test";
            }
        }
    }

    public static void Execute(string[] Params, int chat, string username)
    {

        List = new List("Pie1", "Pie2");
        Dim rnd as new Random();
        Dim randomFruit = List(rnd.Next(0, List1.Count));
        Skyper.SendMessage(chat, randomFruit);
    }
}

谢谢!

1 个答案:

答案 0 :(得分:0)

在类

中移动Execute方法
namespace Skyper.plugins
{
    public static class Help
    {
        public static string Description
        {
            get 
            {
                return "Random Object Test";
            }
        }
        public static void Execute(string[] Params, int chat, string username)
        {
            List<string> List1 = new List<string>() {"Pie1", "Pie2"};
            Random rnd = new Random();
            string randomFruit = List1[rnd.Next(0, List1.Count)];
            Skyper.SendMessage(chat, randomFruit);
        }
    }
}

你不能在类定义之外使用方法,也有过多的结束大括号。

此外,这些线条毫无意义:

List = new List("Pie1", "Pie2");
Dim randomFruit = List(rnd.Next(0, List1.Count));

可能你的意思是

List<string> List1 = new List<string>() {"Pie1", "Pie2"};
string randomFruit = List1[rnd.Next(0, List1.Count)];