Type--variable, constant---------------function, array
First, the data type:
Strings---Put a string of characters. Need to be caused by "".
String s= "456";
String a= "789";
Console WriteLine (a+s);
1 bytes = 8 bits
* Integral type (int)---integer types. 4 byte Long (8 bytes in length) short (2 bytes) Tiny (micro-shaping 1 bytes)
int a = 456;
int b = 789;
Console.WriteLine (A+B);
* Decimal type, floating point type (float,double)
FLOAT: single-precision floating-point type. 4 bytes
Double: dual-precision floating-point type. 8 bytes
Double d = 3.14;
float d =3.14f;
* Boolean type: (BOOL). Logical type, either or. True,false;
BOOL B = true;
bool d = false;
Character type (char). Single character
char c = ' 4 ';
Ii. variables (the amount of value that can be changed during the run)
Defined first, then used.
When you define a variable name, you cannot duplicate it.
(a) Definition:
Data type variable name [= value];
int A;
int B = 20;
(b) Assignment:
Variable name = value
(c) Value:
By using the variable name directly, the values stored in the variable can be taken out.
(iv) General rules for naming variables.
1. Variable names are generally composed of letters, numbers, and underscores.
2. The variable name can begin with only letters or underscores.
3. Variable names cannot be duplicated with system keywords (blue font).
Third, constant (the amount of value cannot be changed during operation)
Literal constants.
Symbol constants. Definition: Add the const keyword to the left of the variable definition.
const int b = 20;
Note: The symbolic constants must be assigned when they are defined.
Application of Symbolic constants: In some repeatedly used complex data, generally like to use constants to replace it, using constants for programming operations.
Four, type conversion.
Computers can only operate on the same type of data, and different types of data cannot be directly computed, and if they are of different types, they need to be converted (auto, force).
int a = 10;
Double b = 3;
Console.wirteline (A/b); First, the value of a 10 into a decimal type 10.0000, and then do the division operation.
Automatic conversion: The computer automatically converts the type according to the calculation data. The principle is that as long as the type is not lost, the data will be transformed.
Tiny->short->int->long->double
Cast: A programmer forces a type to become another type. This forced conversion is implemented when the computer does not automatically convert, but it is possible to lose data.
Grammar:
1. Add parentheses to the left side of the converted data, and write the target type to be converted.
int a = (int) 3.14;
2. Use Convert.toxxx () conversion.
int a = 10;
Double b = 3.0;
int c = A/convert.toint32 (b);
string s = "7896";
int n =conver.toint32 (s);
Basic Types of C #