Type conversion is a processof convetring one type of data to another. There are three ways of doing it, namely implicit explicit and user defined.
|
Implicit Conversions
in C#
The implicit
conversions can occur in a variety of situations like
function invoking, cast expressions, assignments etc.
The implicit conversions can be further classified
into different categories. Implicit Numerical
Conversions
The possible
implicit numerical conversions in C# are shown below.
An implicit enumeration
conversion permits the decimal
integer literal 0 to be
converted to any enum type.
Implicit Reference Conversion
The possible implicit reference
conversions are
Boxing Conversions
Boxing is the
conversion of any value type to object type. Remember
that boxing is an implicit conversion. Boxing a value
of value type like int consists of allocating an
object instance and copying the value of the value
type into that object instance. An example for boxing
is shown below.
A boxing
conversion making a copy of the value being boxed. But
when we convert a reference type to object type, the
object continues to reference the same instance.
|