.NET and X# permit an enhanced casting of variables. Using the casting the compiler can will check the properties and methods of the object.
local oObject as object local oDateTime as object oObject := DateTime.Now oObject:AddYears( 1 ) // compiler error here ( ( DateTime ) oObject ):AddYears( 1 ) // works oDateTime := oObject // compiler error here oDateTime := ( DateTime ) oObject //works
astype statement is an advanced form of casting, but if works only on datatypes that can be null:
oString := oObject asytype string
In the case that oObject is not a string, the null value is assigned to the oString variable.
The following code will not work as
DateTime cannot have a null value:
local oDateTime as DateTime oDateTime := oObject astype DateTime
This code will only work if you use
Nullable<DateTime> instead of