C# Elementary Learning

Insert picture description here
Insert picture description here

The console display code:
Console.Writeline("Haha, I'm so handsome!");
Console.Readkey();
This string of codes means to display "Haha, I'm so handsome!" and wait for users Press any key to exit!

Insert picture description here
Insert picture description here
Insert picture description here

///This is an annotation for the method! ! !
Insert picture description here
Folding code
#region
#endregion
Insert picture description here
MSIL: Microsoft Intermediate Language
CLR: Common Language Runtime
CLS: Common Language Specification
CTS: Common Type System
JIT: Just In Time
Ctrl+K +C: Quick comment
Insert picture description here
Insert picture description here
Int integer double decimal char character
String string decimal money decimal
Double and decimal are both decimals, but the precision is different.
Float floating-point constants, in general, represent real numbers

int @int=3;
you can assign int to 3, at this time int is the variable name;

Static void Main(string[] args) In
this, Main is the method name,
String[] args are the method parameters.

String name="Old Yang";
Console.WriteLine("Hello"+name); At
this time, the + plays the role of connection;

How to make the user into a digital string
Insert picture description here
escape, + a special character escape
\ n newline
\ b represents backspace
\ represents a
\ t horizontal tab
plurality escape only in the Add @ in front

Implicit and explicit conversion

Insert picture description here

The placeholder {0} represents a placeholder
{0}, a: indicates that the previous placeholder is filled in with a.
(Data type name) the value to be converted;
Insert picture description here

Such as: Insert picture description here
Convert.ToInt (data converted into int)
Try-catch

Num++ itself plus 1

Number=Num++, the result is 10, calculate first, then add 1
Num=num++, the result is 11
Int Number=++Num+10, the result is 21, add first before the calculation.
Comprehensive consideration: ++ has priority after +

Boolean (bool) type:
True or false

If either expression 1 or expression 2 is false, the logical AND is false, and
if both expressions are true, the logical AND is true.
If the two expressions are false, the logical AND is false.

If one of the expressions is true, the result of the logical OR is true.
If both are false, the result of the logical OR is false.

If the expression is true, the non-expression is false;

        Console.WriteLine("请您输入账号:");
        string ID = Console.ReadLine();
        Console.WriteLine("请您输入密码:");
        string password = Console.ReadLine();//接收数据
        if (ID == "admin" && password == "12345")//if语句判断是否登录成功
        {
            Console.WriteLine("登录成功");
        }
        else
        {
            Console.WriteLine("密码或账号不正确");
        }
        Console.ReadKey();

F11 debug one by one
F10 debug step by step

For loop code display:
For (int i=0;i<100;i++)
{ Console.WriteLine("Little Yang is handsome") // (loop body) } Console.ReadKey();


Polymorphism: The ability to make the object express multiple types;
polymorphism; The method name of the subclass can be the same as the method name of the parent class; but a green line will appear.
How to solve the defect : You can use the modifier of the subclass method It will be solved by adding new later.
No matter whether you add new or not, it will not affect the use.

The second method is to add Virtual after the modifier of the parent class method. (Virtual method)

Insert picture description here
Insert picture description here

foreach: loop traversal

Guess you like

Origin blog.csdn.net/weixin_48850992/article/details/107369806