Why am I not allowed to do this:
private Base Property => m_IsAbsolute ? new A() : new B();
Compiler complains about 'No implicit conversion between A and B
I can fix that by casting B
to Base
, but why on earth would I need to do that?
While I am allowed to do this:
private Base Property2
{
get
{
if (m_IsAbsolute)
{
return new A();
}
return new B();
}
}
For reference the classes used in above example:
class Base
{
}
class A : Base
{
}
class B : Base
{
}