In Microsoft Dynamics AX2012, the X++ language provides the as and is expression operators to control downcast assignments. Downcast assignments involve class or table inheritance.
Assignment statements that implicitly downcast can cause errors that are hard for the programmer to predict or diagnose.
You can use the as keyword to make your downcasts explicit.
You can use the is keyword to test whether a downcast is valid at run time.
as Example
Assignment statements that implicitly downcast can cause errors that are hard for the programmer to predict or diagnose.
You can use the as keyword to make your downcasts explicit.
You can use the is keyword to test whether a downcast is valid at run time.
as Example
static void AsTestJob33(Args _args)
{
BaseClass basec;
DerivedClass derivedc;
BottomClass bottomc; ;
derivedc = new DerivedClass();
basec = derivedc;
derivedc = basec as DerivedClass;
bottomc = new BottomClass();
bottomc = basec as DerivedClass;
}is Example
static void IsKeywordJob46(Args _args)
{
DerivedClass derivedc;
BaseClass basec;
basec = new DerivedClass(); // An upcast.
if (basec IS DerivedClass)
{
info("Test 1: (basec IS DerivedClass) is true. Good.");
derivedc = basec AS DerivedClass;
}
basec = new BaseClass();
if (!(basec IS DerivedClass))
{
info("Test 2: (!(basec IS DerivedClass) is true. Good."));
}
}
