我们可以在接口中使用字段事件吗?我用这个,我没有任何错误
class Program
{
public delegate string MyDelegate(string a);
public static void Main(string[] args)
{
}
public interface face
{
event MyDelegate ab;
}
}
Run Code Online (Sandbox Code Playgroud)
接口不能声明字段,但它们可以声明事件.
接口由方法,属性,事件,索引器或这四种成员类型的任意组合组成.接口不能包含常量,字段,运算符,实例构造函数,析构函数或类型.
有关如何在接口中声明事件然后在类中实现它的信息,请参阅本教程: