C # variable

Data type 1), integer type: int can only store integers, not decimals.
2). Decimal type: double can store both integers and decimals. The number of digits after the decimal point is 15~16.
3), money type: decimal: used for crude money, need to add an m after the value.
4), string type: string, used to store multiple texts, and can also store empty characters The value of string type needs to be quoted by double quotation marks.
This double quotation mark must be a double quotation mark in English half-width state.
5) Character type: char, used to store a single character, at most and at least one Characters, can not be stored empty.
Character type values ​​need to be enclosed in single quotes. Single quotation marks in English half-width state.

 1 static < span style="color: #0000ff;">void Main(string[] args )

2 {
3 //Variable type variable name;
4 int number;
5 //Variable name = value;
6 number = 100;
7
8 //Use double quotes for string assignment
9 string zsName = "Zhang San";
10 string s = ""; // The string can be stored as empty
11
12 //Characters cannot be empty assignments with single quotes
13 char gender = 'Male';
14 //Type of money
15 decimal money = 2200m;
16
17
18 }

The function of the “+” sign:

1), connection : When there is a string on both sides of the + sign, the + sign acts as a connection.
2), Add: when there are numbers on both sides

Placeholder

1 int n1 = 10;

2 int n2 = 20;
3 int n3 = 30;
4
5 Console.WriteLine("The first number is {0}, the second number is {1}, and the third number is {2}", n1, n2, n3);
6 Console.ReadKey();

Result:

Share a picture

Accept output data

 Console.WriteLine("Please enter your name:");

string name = Console.ReadLine();

Console.WriteLine(
"Your name is: {0}< /span>", name);
Console.ReadKey();

Share a picture

 1 static void Main(string[] args)

2 {
3 //Variable type variable name;
4 int number;
5 //Variable name = value;
6 number = 100;
7
8 //Use double quotes for string assignment
9 string zsName = "Zhang San";
10 string s = ""; // The string can be stored as empty
11
12 //Characters cannot be empty assignments with single quotes
13 char gender = 'Male';
14 //Type of money
15 decimal money = 2200m;
16
17
18 }

1< /span> int n1 = 10;

2 int n2 = 20;
3 int n3 = 30;
4
5 Console.WriteLine("The first number is {0}, the second number is {1}, and the third number is {2}", n1, n2, n3);
6 Console.ReadKey();

 Console.WriteLine(< span style="color: #800000;">"Please enter your name: ");

string name = Console.ReadLine();

Console.WriteLine(
"Your name is: {0}< /span>", name);
Console.ReadKey();

Leave a Comment

Your email address will not be published.