错误类型或命名空间定义,或命令中应包含的文件结尾:笑话
本文关键字:包含 文件 笑话 结尾 命名空间 类型 定义 命令 错误 | 更新日期: 2023-09-27 18:32:32
我的代码收到此错误:错误类型或命名空间定义,或命令中预期的文件结尾:笑话。
我正在尝试从列表中选择随机的东西。这是通过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);
}
}
谢谢!
在类内移动 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)];