Type Conversion

The meaning of the variable is determined by the way in which this data is interpreted. The simplest example of this is the char type. This type represents a character in the Unicode character set using a number. In fact, this number is stored in exactly the same way as a ushort — both of them store a number between 0 and 65535.
However, in general, the different types of variables use varying schemes to represent data. This implies that even if it were possible to place the sequence of bits from one variable into a variable of a different type (perhaps they use the same amount of storage, or perhaps the target type has enough storage space to include all the source bits), the results might not be what you expect!
Instead of this one – to – one mapping of bits from one variable into another, you need to use type conversion on the data. Type conversion takes two forms:
Implicit conversion: Conversion from type A to type B is possible in all circumstances, and the rules for performing the conversion are simple enough for you to trust in the compiler.

Explicit conversion: Conversion from type A to type B is only possible in certain circumstances or where the rules for conversion are complicated enough to merit additional processing of some kind.


You may also like...