Explicit casts

Top  Previous  Next

What is translated > Assignments > Explicit casts


Generally, if a variable of one type is assigned to another variable with another type this is possible without problems, if no information is lost. For example, if a shortint variable is assigned to an integer variable, there is no problem, because the size of shortint is one byte  and the size of an integer variable is at least two bytes. If the assignment goes the other way round however in C# an explicit cast is necessary:


  si : shortint;

  i : integer;


  i := si;

  si := i;


becomes to:


  sbyte si = 0;

  int i = 0;

  i = si;

  si = (sbyte) i;


Delphi2C# always inserts the according casts, also when such casts are necessary to pass parameters to functions.





This page belongs to the Delphi2C# Documentation

Delphi2C# home  Content