User Tools

Site Tools



This shows you the differences between two versions of the page.

Link to this comparison view

casting_astype [2018/04/22 11:45] (current)
wolfgangriedmann created
Line 1: Line 1:
 +.NET and X# permit an enhanced casting of variables. Using the casting the compiler can will check the properties and methods of the object.
 +<code>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</code>
 +The ''astype'' statement is an advanced form of casting, but if works only on datatypes that can be null:
 +<code>oString := oObject asytype string</code>
 +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:
 +<code>local oDateTime as DateTime
 +oDateTime := oObject astype DateTime</code>
 +This code will only work if you use ''Nullable<DateTime>'' instead of ''DateTime''
casting_astype.txt ยท Last modified: 2018/04/22 11:45 by wolfgangriedmann