c# - 如何将委托(delegate)添加到接口(interface) C#

标签 c# interface delegates

我的类(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/

相关文章:

C# 从数组中删除重复的字符

c# - MonoDroid 中带有 AOP (PostSharp) 的 IoC

c# - Unity3d error CS1061 : Type x does not contain a definition for y. 但是确实如此吗?

java - Java是如何实现接口(interface)多态的?

iphone - iOS设计: Using the delegate pattern in a library

c# - 如何在回发时捕获并触发用户控件的自定义事件

c# - 带正则表达式的匹配表

java - Java 中的接口(interface)和抽象类

ios - 如何在 UISplitViewController 中分配 MasterViewController 的子菜单的委托(delegate)

c# - 委托(delegate)事件问题