O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implicit Versus Explicit Conversions

Simply stated, conversions are a way to treat an expression as being of a specified type. This gives rise to two different situations: Either the conversion is statically known by the compiler to be safe (no data loss can occur) or such guarantees do not exist.

In the former case, implicit conversions are permitted by the compiler. Primitive types form a good playground to illustrate this. For example, given an int variable, it’s possible to treat it as if it were a long because all Int32 values definitely fit in the range of the Int64 type. This particular conversion is a representation-changing conversion that needs runtime assistance because we’re stuffing a 4-byte value in an 8-byte one:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required