Dlaczego nie możemy użyć konstruktora z parametrem w klasach pochodnych
Dlaczego to nie jest możliwe? Otrzymuję następujący błąd kompilatora podczas tworzenia instancji „DerivedClass” za pomocą parametru constructor:
„GenericParameterizedConstructor.DerivedClass” nie zawiera konstruktora, który pobiera 1 argument
Ale wywołanie bardzo podobnej metody działa.
Czemu?
class Program
{
static void Main(string[] args)
{
// This one produces a compile error
// DerivedClass cls = new DerivedClass("Some value");
// This one works;
DerivedClass cls2 = new DerivedClass();
cls2.SomeMethod("Some value");
}
}
public class BaseClass<T>
{
internal T Value;
public BaseClass()
{
}
public BaseClass(T value)
{
this.Value = value;
}
public void SomeMethod(T value)
{
this.Value = value;
}
}
public class DerivedClass : BaseClass<String>
{
}