为什么Funky<T>
中的构造函数过载与参数动作有关,但子类FunkyAction
没有?作为构造函数中的泛型类型给出了编译错误
class Funky<T>
{
readonly T _data;
public Funky(T data)
{
_data = data;
}
public Funky(Action action, bool imJustAnOverload)
: this(action) // cannot convert from 'System.Action' to 'T'
{
}
}
class FunkyAction : Funky<Action>
{
public FunkyAction(Action action)
: base(action) // no compile error
{
}
}
因为'action'! ='T'在你的基类中。 'T'可以是任何东西。在你的派生类中'T'是一个'Action'。 –