Why does line 3 cause Class Cast Exception where as line 4 doesn't
Thx [ April 06, 2004: Message edited by: Mary Cole ]
Ashok C. Mohan
posted 11 years ago
In line 3 u r trying to cast a base class object to a derived class,which causes the compile time error,as this does not make any sense.(Only derived class objects can be casted to base class objects. In line 4 though u r trying to cast the interface reference to the base class,the underlying object to which the reference i is pointing is a base class object,so casting a base class object to itself does not cause a compile time error.
Do not dwell in the past, do not dream of the future, concentrate the mind on the present moment.