Variables in the C # language
Concept: A piece of memory that stores data, and the data content of that memory area can change
Three elements of a variable: data type, variable name, variable value
First declaration, then assign the value
Variable declaration: Specifies a piece of memory space for storing data
Syntax: Data type variable name
For example: int number; For storing integers
Assignment of variables:
For example: int number; number=6; For storing integers
Variable naming
Hard Requirements:
1. Variables can only be composed of numbers, letters, underscores
2. Variable names must not start with a number
3. The name cannot be the same as the keyword
4. Variable names must not be the same in the same function
Soft requirements:
1. Variable name to be able to look at the text to understand
2. Variable name first letter lowercase
3. In addition to the first word, the other single first letter capitalization
Data types in the C # language
1.char character type
Unlimited number of words (Chinese characters, letters, numbers, punctuation marks)
2.string String Type
Unlimited number of words (Chinese characters, letters, numbers, punctuation marks)
notation in pairs of double quotation marks
Data example "Han" "" "Hello,world"
3.in integer type
Integral type, used to represent an integer
Write the way to write directly
Data Example 0 100-1-100
4.double Decimal Type
Used to represent numbers that contain decimals
Write the way to write directly
Data example 0.0 1.1-1.1-1.123 correct
Conversion of data:
1. Int+int=int (Discard decimal part.)
Double+int=double
The result of a 2.string type is a string type, which can be operated on with any type
3. Convert any type to string
Data to be converted. ToString (); int a = 10;
STRINGB = A.tostring ();
Convert 4.int to Double
implicit conversion inta=123;
doubled = A;
Convert 5.double to int
Explicit conversion of Double A = 3.14
int d = (int) A;
6.string converts to numbers (int)
Int. Parse (string to be converted); return type int
Convert 7.string to Double
Double. Parse (string to be converted); return type is double
Recognize variables and data types in the C # language