我的类(class)需要一些委托(delegate)。
我想使用界面来“提醒”我设置这些委托(delegate)。
怎么做?
我的类(class)是这样的:
public class ClsPictures : myInterface
{
// Implementing the IProcess interface
public event UpdateStatusEventHandler UpdateStatusText;
public delegate void UpdateStatusEventHandler(string Status);
public event StartedEventHandler Started;
public delegate void StartedEventHandler();
}
我需要一个接口(interface)来强制这些委托(delegate):
public interface myInterface
{
// ?????
}
最佳答案
那些正在声明委托(delegate)类型。它们不属于界面。不过,使用那些委托(delegate)类型的事件可以放在接口(interface)中:
public delegate void UpdateStatusEventHandler(string status);
public delegate void StartedEventHandler();
public interface IMyInterface
{
event UpdateStatusEventHandler StatusUpdated;
event StartedEventHandler Started;
}
实现不会(也不应该)重新声明委托(delegate)类型,就像它不会重新声明接口(interface)中使用的任何其他类型一样。
关于c# - 如何将委托(delegate)添加到接口(interface) C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3948721/