Type conversion

SSharp S# API

DropDown image DropDownHover image Collapse image Expand image CollapseAll image ExpandAll image Copy image CopyHover image

Even though S# is dynamically typed language there are cases when a value should be casted to a type explicitly. The type conversion operator is of the following form:

 

( Expression1 Expression2;

Where

  • Expression1 - any valid expression which evaluates to .NET Type,
  • Expression2 - any valid expression, value of which will be converted.

Examples:
 

 (string)23;
 

 s = string;
 b = (s) 23; // b = "23";

Any type conversion during script execution is performed via the runtime Binder. The above shown examples are simply syntactic shortcuts for the following calls:

 

RuntimeHost.Binder.ConvertTo(23, string);