first understand
declare variables
Declaring a variable is to specify the name and type of the variable. The declaration of the variable is very important. The undeclared variable itself is illegal and cannot be used in the program.
Variable Naming Rules
Variables can only consist of numbers, letters, and underscores
The first character of the variable name can only be letters and underscores, not numbers
Cannot use c# keywords as variable names
integer type
type name
sbyte: 8-bit signed integer
short: 16-bit signed integer
int: 32-bit signed integer
long: 64-bit signed integer
byte
ushort
uint
head
practise
int number=1;
Console.WriteLine(number);
floating point type
type name
float: 32 bits, precision 7 bits
double: 64 bits, precision 15
decimal: 128 bits, precision 28 bits
practise
double number=1.1;
tips
If no setting is made, the value containing the decimal point is double by default, if it is to be converted to float (f), double (d), decimal (m)
decimal s=1.12m;
Boolean type
bool
bool flag=true;
character type
type name
Char
string
escape character
\n: carriage return line feed
\":Double quotes
\b: backspace
\r: carriage return
\f: Form feed
practise
string a="c#是世界上最好的语言";
variable scope
Member variables
static variable
For static variables, in addition to being used in the class that defines it, you can also use "class name. static variable" in other classes
static int a=100;
instance variable
int a=100;
local variable
Variables defined between braces are called local variables
little practice
Console.WriteLine("输入字符串");
string number = Console.ReadLine();
Console.WriteLine("字符串为"+number);
Console.ReadLine();
int a = 10;
int b = 20;
int temp=a;
a=b;
b = temp;
Console.WriteLine("a的值{0},b的值{1}", a, b);
Console.ReadLine();