Viva64 Send comments on this topic.
Implicit type conversion

Glossary Item Box

Implicit type conversion, also known as "coercion", is an automatic type conversion by the compiler. Implicit conversions do not require any operator. They are automatically performed when a value is copied to a compatible type. In a mixed type expression, a subtype s will be converted to a supertype t or some subtypes s1, s2, ... will be converted to a supertype t (maybe none of the si is of type t) at runtime so that the program will run correctly. For example:

double d;
long l;
int i;
if (d > i) d = i;
if (i > l) l = i;
if (d == l) d *= 2;

Although d, l and i belong to different datatypes, they will be automatically converted to the same datatype each time a comparison or assignment is executed.

See also:

explicit type conversion

Converting Overview (MSDN); Type Conversion Tables (MSDN); Explicit conversion (MSDN); Usual Arithmetic Conversions (MSDN)