Downcast will fail. : Object Cast « Class Interface « C# / C Sharp

Downcast will fail.


class Employee { }
class ContractEmployee : Employee { }
class CastExample3
    public static void Main ()
        ContractEmployee ce = (ContractEmployee)new Employee(); 


Related examples in the same category

1.Casting Objects
2.This code raises an exception at run time because of an invalid cast
3.Casting objects: upcastCasting objects: upcast
4.Casting objects: downcastCasting objects: downcast
5.Variables of type object can accept values of any data type