high-precision data types that convert to low-precision data types are display conversions, and low-precision conversions to high-precision are implicit conversions. Warm tip: You cannot say coercion type conversions are from low precision to high precision. int a=666;
float b= (float) A;Conversions from A to B are low-precision to high-precision conversions, implicit conversions, but also cast (float), and of course not. 1. Implicit Conversion Example:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceAn expression {classProgram {Static voidMain (string[] args) { intx =3; floaty; Y=x; Console.WriteLine (y); Console.readkey (); } }}
Output Result: 3
Variables in C # must be initialized if they need to be output, otherwise they cannot be run, not output is not initialized
2. Display Conversion Example:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceAn expression {classProgram {Static voidMain (string[] args) { intx; floaty=1.2f; X= (inty;//high precision to low precision requires forced type conversion Console.WriteLine (x); Console.readkey (); //The C # decimal number defaults to the double type, so float x=1.2; The system prompts you not to convert double= to float type, you need to add an F suffix to create this type } }}
C # implicit conversion and Display conversion Example--c# basics