Is it possible to have an abstract property which returns a type defined in the derived class:
abstract class baseClass
{
public abstract e_Type type { get; }
}
class derived : baseClass
{
public enum e_Type
{
type1,
type2
}
private e_Type _type;
public e_Type type { get { return _type; } }
}
or must I return an int and map it in the derived class. Any other suggestions welcome.
Sure you can:
abstract class BaseClass<T>
{
public abstract T Type { get; }
}
class Derived : BaseClass<EType>
{
public enum EType
{
type1,
type2
}
private EType _type;
public override EType Type { get { return _type; } }
}
You don't even need to declare it as abstract:
class BaseClass<T> {
private T _type;
public T Type { get { return _type; } }
}
which you can then use as:
BaseClass<EType> classInst = new BaseClass<EType>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With