【发布时间】:2012-03-12 23:53:04
【问题描述】:
我有一个具有类型约束的abstract 类。但我也想让abstract 类实现一个接口。
例如:
public abstract class PostEvent<TPost> : IDomainEvent, where TPost : Post, new()
无法编译。
我不想要这个:
public abstract class PostEvent<TPost> where TPost : Post, IDomainEvent, new()
因为那意味着TPost : IDomainEvent
我想要PostEvent : IDomainEvent
语法是什么?
【问题讨论】:
-
我目前没有设置来测试它,但您可以尝试删除
IDomainEvent和where之间的逗号。
标签: c# generics c#-4.0 interface type-constraints