相关疑难解决方法(0)

C#Generics不允许委托类型约束

是否可以在C#中定义一个类

class GenericCollection<T> : SomeBaseCollection<T> where T : Delegate
Run Code Online (Sandbox Code Playgroud)

我无法为我的生活在.NET 3.5中完成这一切.我试过用

delegate, Delegate, Action<T> and Func<T, T>

在我看来,这应该是允许的某种方式.我正在尝试实现自己的EventQueue.

我最终只是这样做[原始近似注意你].

internal delegate void DWork();

class EventQueue {
    private Queue<DWork> eventq;
}
Run Code Online (Sandbox Code Playgroud)

但是后来我失去了为不同类型的函数重用相同定义的能力.

思考?

c# generics events delegates constraints

76
推荐指数
4
解决办法
3万
查看次数

标签 统计

c# ×1

constraints ×1

delegates ×1

events ×1

generics ×1