1.

Distinguish between explicit and implicit type conversion

Answer» 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.For example, the values of ushort and char are effectively interchangeable, because both store a number between 0 and 65535. You can convert values between these types implicitly.There are many implicit conversions of simple types; bool and string have no implicit conversions, but the numeric types have a few. For reference, the following table shows the numeric conversions that the compiler can perform implicitly (remember that chars are stored as numbers, so char counts as a numeric type).TYPE CAN SAFELY BE CONVERTED TObyte short, ushort, int, uint, long, ulong, float, double, decimalsbyte short, int, long, float, double, decimalshort int, long, float, double, decimalushort int, uint, long, ulong, float, double, decimalint long, float, double, decimaluint long, ulong, float, double, decimallong float, double, decimalulong float, double, decimalfloat doublechar ushort, int, uint, long, ulong, float, double, decimalExplicit conversion:\xa0Explicit 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;In the above statement, we have to specify the type operator (int) when converting from double to int else the compiler will throw an error.


Discussion

No Comment Found