Cast

From D Wiki
Revision as of 17:09, 13 February 2013 by W0rp (talk | contribs) (Added a page just for this one feature of D, as part of my personal campaign to fill the wiki with easy to find information.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Casting class types

Casting to a class type T can from a value can be achieved with the following:

cast(T) value

Casting will result in a null reference when the cast cannot be made. (There is no instanceof operator, because it is not needed.)

MyType castedValue = cast(MyType) someValue;

if (castedValue != null)
{
    /* use the casted value */
}