TRYAS (explicit type conversion)

Top  Previous  Next

 

<expression> TRYAS <type>

 

TRYAS

used for explicit casting.

type

the signature of a type

Although Clarion performs type conversions implicitly, there are times when you may need to perform an explicit conversion. The AS and TRYAS keywords are used to perform explicit conversions between compatible types.

 

TRYAS uses Clarion Type Conversion rules for the casting of value-types, but throws an exception if the casting is impossible, but AS will return null in this case.

 

AS and TRYAS operators are new to Clarion .NET. These operators are used for explicit casting. The syntax is following:

 

Both operators try to cast the specified expression to the given type. The difference between these operators is the following:

 

• TRYAS throws an exception if the casting is impossible, but AS return null in this case.

• AS operator doesn’t accept value-types for <type>

 

Also, TRYAS uses Clarion Type Conversion rules for the casting of value-types.

 

Example:

 

A LONG

 CODE

 A = ('10' & '20') TRYAS LONG   !  Casting to long

 

See Also: AS (Explicit type conversion)