A basic knowledge, but not everyone can make it clear.
When a subclass object is converted to a parent class, it can be implicitly converted.
When a parent class object is converted to a subclass, the conversion must be displayed. If the actual object to which the parent class type points is a parent class object rather than a subclass object, the runtime error invaildcastexception occurs.
Use the as operator to avoid invalidcastexception, but return NULL if the conversion fails.
Mytypea = New Mytypea ();
Mytypeb B1 = (Mytypeb);
Mytypeb B2 = A As Mytypeb;
Mytypeb is a subclass of mytypea. The second sentence will cause invalidcastexception, while the third sentence will not make an error, but B2 is a null reference.
There is also an is operator, which can determine whether the type of the object actually referenced by the variable is a specified type. Note that it is the actually referenced object type, regardless of whether the reference is an abstract class or an interface.
When a null value is actually referenced, a false value is returned.