E
Erik Frey
Hello,
Say I have the following two classes:
class Base
{
}
class Inherited : Base
{
}
Then I create two arrays of each, and fill the base array with an inherited
instance:
Inherited[] inheriteds = new Inherited[1];
Base[] bases = new Base[1];
bases[0] = new Inherited();
Why is it possible to do the following narrowing conversion:
inheriteds[0] = (Inherited) bases[0];
But NOT possible to do the following narrowing conversion:
inheriteds = (Inherited[]) bases;
Furthermore, why is this a run-time error and not a compile time error?
Thanks,
Erik
Say I have the following two classes:
class Base
{
}
class Inherited : Base
{
}
Then I create two arrays of each, and fill the base array with an inherited
instance:
Inherited[] inheriteds = new Inherited[1];
Base[] bases = new Base[1];
bases[0] = new Inherited();
Why is it possible to do the following narrowing conversion:
inheriteds[0] = (Inherited) bases[0];
But NOT possible to do the following narrowing conversion:
inheriteds = (Inherited[]) bases;
Furthermore, why is this a run-time error and not a compile time error?
Thanks,
Erik