In the video teaching after the understanding of learning, if the wrong to ask the great God advice
A type conversion in the C # language is the conversion of one data to another type of data.
The data types in the C # language are mainly:
Char type (character type);
Type string (string type);
int type (integer type);
Double type (decimal type);
Type conversions are divided into three main types:
1: Convert any type to string type;
The conversion code is written in the form: data to be converted. Tostring ();
A, the data to be converted here refers to the data or variables that need to be converted. The following ToString () is a fixed writing.
The return type when the conversion is complete is string type.
Example:
int a = 10;
String B = A. ToString ();
PS: Variables of type int are not changed during the conversion process.
The 2:int type and the double type are mutually transferred;
The value range of the ps:double type is greater than the range of values of type int.
PS: The principle of conversion between numeric types: a small range of values to convert to a large range of numeric types, no need for additional writing code, the computer will automatically complete, such as implicit conversion, and conversely, the value range of large conversion to a small range of values, you need to write extra code, the computer does not automatically complete, Such called display transformations, also called casts. Casting can cause data loss. The notation for displaying the transformation is to write two parentheses before the data to be converted, and write the type that needs to be converted in parentheses.
Examples of implicit conversions:
int a = 123;
Double d = A;
Double d = 123;
Parsing, the value range of type int is less than the range of values of type double, so implicit conversions are used without writing extra code.
Show Conversion Examples:
Double A = 3.14;
int d = (int) A;
Parse: The value range of a double type is greater than the int type, so the display transformation is used to return the result to Int.
The 3.string type is converted to a numeric type;
(1): string converted to int type:
The number of writes is: Int.parse (the string to be converted), and the returned result is int.
Example:
Console.Write ("");
int a = Int.parse (Console.ReadLine ());
(2): string is converted to double type:
The written format is: Double.Parse (the string to be converted), and the returned result is double.
Example:
Console.Write ("");
Double b = Double.Parse (Console.ReadLine ());
The above is to see the video after the summary of the C # language common type conversion, if there is a mistake, ask the great God advice.
Understanding type conversions in the C # language----Beginner's understanding, please teach the great God