Export (0) Print
Expand All

6. Conversions

Visual Studio .NET 2003

A conversion enables an expression of one type to be treated as another type. Conversions can be implicit or explicit, and this determines whether an explicit cast is required. For instance, the conversion from type int to type long is implicit, so expressions of type int can implicitly be treated as type long. The opposite conversion, from type long to type int, is explicit and so an explicit cast is required.

int a = 123;
long b = a;         // implicit conversion from int to long
int c = (int) b;   // explicit conversion from long to int

Some conversions are defined by the language. Programs may also define their own conversions (Section 6.4).

Show:
© 2014 Microsoft