Implicit Explicit Conversion Operators in C#
Conversion between data types can be done in two ways by casting:
- Implicit casting
- Explicit casting
Implicit casting
Implicit casting doesn't require a casting operator. This casting is normally used when converting data from smaller integral types to larger or derived types to the base type.
int x = 123;
double y = x;
In the above statement, the conversion of data from int to double is done implicitly, in other words programmer don't need to specify any type operators.
Explicit casting
Explicit casting requires a casting operator. This casting is normally used when converting a
double to int or a base type to a derived type.double y = 123;
int x = (int)y;
Comments
Post a Comment