Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What is the difference between implicit conversion and explicit conversion?
What is the difference between implicit conversion and explicit conversion?

Implicit conversion means that the system performs the conversion by itself when converting from a small range of values ??to a large range, without human intervention. Explicit conversion means that the programmer must perform the conversion, or the system cannot perform automatic conversion.

If:

int->long is an implicit conversion!

int num1 =6;

long num2 = 7;

var result = num1+num2;

This is due to the difference between int and When long is calculated, it is found that the two types are different. The system automatically converts int to long, so the result is naturally long! And var result = (long)num1+num2; is an explicit conversion, and the programmer intervenes! But in our case, explicit conversion is not used, but implicit conversion is performed by the system. But for long->int, explicit conversion must be used:

var result = num1+(int)num2; In this case, the system cannot convert it by itself, so explicit conversion must be performed.

The difference between implicit conversion and explicit conversion is that implicit conversion is automatically performed by the system, while explicit conversion is performed by the programmer.