Reference Type Conversions

Reference type conversions are performed the same as value type conversions. However, there are more conversion options for reference types. The additional options are related to the class inheritance capabilities of reference types.

For C++ Programmers

C++ has conversion constructors that allow assignment of one type to another. These conversion constructors can contain an explicit modifier to force them to be normal instance constructors. Although C# doesn't have this feature, the same effect can be achieved by the use of implicit and explicit operator implementations within a class definition.

Conversions from a derived class to a base class are implicit. This comes from the fact that the derived class has an “is ...

Get C# Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.