【发布时间】:2012-01-30 11:58:32
【问题描述】:
用我认为是非常简单的一段代码,我自己就开始了。代码胜于雄辩,就是这样。
public interface IResponse
{
IResult Result { get; set; }
}
public class Response<T> : IResponse
where T : IResult
{
public T Result { get; set; }
// COMPILER ERROR: Property 'Result' cannot be implemented property from interface 'IResponse'. Type should be 'IResult'.
}
编译器不允许我这样做,因为 IResponse 要求 Result 是 IResult,但是我想利用实现类中的泛型并将结果强输入到 T。这是不可能的,还是我错过了有什么小事吗?
【问题讨论】:
标签: c# .net generics interface