在接口中使用
default(T)
。 显式地 实现该接口。 结果不能编译。public interface IWhatever<T>
{
List<T> Foo(T BarObject = default(T));
}
public class ConcreteWhatever: IWhatever<ConcreteWhatever>
{
List<ConcreteWhatever> Foo(ConcreteWhatever BarObject = default(T)) {}
}
我完全期望得到default(ConcreteWhatever)
,但实际上我收到的是default(T)
,这导致了编译错误。
我只能将default(T)
替换为null
,然后一切都好了。但是这太丑陋了。为什么会发生这种情况?
Foo
的定义中添加public
修饰符。因为你的接口是公共的,所以public
是隐含的。 - IAbstract