C# study diary 1

Basic knowledge:

(1) What is abstraction? (The abstract result is a class): The process of extracting the core key parts of the problem and ignoring the unimportant parts.

          Object: A specific thing. eg: Zhang San, Li Si

           Class: something abstract. eg: Chinese

(2) Three major characteristics of object-oriented: encapsulation, inheritance, polymorphism

(3) What is encapsulation? What to use to encapsulate? How to package? : Classes and objects are the basic units of object-oriented programming. Access modifiers: public (public) protected (accessible only if there is an inheritance relationship) private (private) internal (collection internal). The class contains: fields, constructors (assign initial values ​​to fields), attributes (set write get read) methods

(4) Inheritance: A form of parent-child relationship between two classes.

(5) Polymorphism: Many polymorphisms are implemented by relying on inheritance relationships

        Method coverage: If there is a method with the same name in the parent class in the subclass, the subclass is called first

        Method overloading: In the same class, there are multiple methods with the same method name and different number or types of parameters

        Method rewriting: The subclass rewrites the method modified by the virtual keyword in the parent class. The overridden method in the subclass is decorated with override (method overriding is also method rewriting)

         Abstract: abstract In a class, if it contains an abstract method, the class must be an abstract class

         Interface: An interface is a special abstract class with only abstract methods

1.using System; is the namespace --> folder is equivalent to the "system folder", in which there are many programs that Microsoft helps you write.

2. The namespace keyword is followed by the project name. Below the namespace is the class written by myself

3. static void Main(string[] args) is the entry of the program, a program can only have one entry of the program

4.Console.WriteLine() is equivalent to System.out.print() in java, which can be displayed by entering cw and pressing the tab key twice

If there are two projects in a solution, the bold black one is the default startup item. If you want MySecondProject below to be the default startup item, right-click the project and select it as the default startup item.

5. The constructor has the same name as the class. There is no return value keyword, function: assign an initial value to the field. The no-argument constructor does not need to be called and is executed automatically.

Constructors can be divided into no-argument constructors and argument-argument constructors. Argument-parameter constructors need to pass parameters when they are called.

6. Method: what is the class composed of (1) field (2) method, which is used to realize a certain function

In programming, the rules for naming variables or methods:

(1) Hump method:

For example: name the field, public int intAge

(2) Pascal method

For example: to name a class or method, public void DisplayInfo(){}

Method: There are two types

(1) Object method for object call

(2) Static method In a class, a static method calls another static method, which can be called directly

                        If not in a class, the static method calls another static method, the class name. method name is required to call

method components

(1) The name of the method

(2) Each method has a "method body". If there is no return value, add the void keyword. If there is a return value, add the type keyword of the return value

Guess you like

Origin blog.csdn.net/m0_56632799/article/details/127911990