Adhere to ASP.NET - (Nine)

xiaoxiao2021-03-06  54

Object and code multiplex

First, the statement of the object:

The declaration with the variable is exactly the same, and the difference is that the declaration cannot be used immediately, and can only be used after the object is created.

For a non-existing object reference, and the value is NULL, indicating any object from the heap.

EG: Car Jeepcar = NULL;

After using the object, I hope to use it later, if I don't delete it, I only need to set the value null.

Second, the method and attribute of the object:

Constructor definition and use.

Overload of functions

Operator overload:

Public Static ClassType Operator (Object LHS, Object RHS) {

ClasStype C; Return C;

}

Sharing members and class relations

First, share members

There are two ways to use the shared properties: instance. Property class. Properties

Static constructor.

Second, sharing method

Class relationship

First, the association: - Uses a

1. Create a member variable in class A, receive, create and / or return to B objects;

2. Define a data member in class A, as an object of class B;

AC and borrowed between classes.

Second, including - HAS A

Define objects in a class into objects derived from another class.

Third, inheritance --IS A

Abstract classes cannot be inherited.

The class of inheritance interface must implement the method defined in the interface. A class can inherit 0 or more interfaces.

Fourth, virtual function:

Public Virtual Bool Driver () {};

Virtual tells the compiler that this method can be rewritten in the inheritance class, but it is not necessarily overwritten. Such rewriting in the inheritance class:

Public override bool driver () {};

Override tells the compiler, we don't want to use the original version, but directly use the current version.

Another situation is that the function of the base class is not a virtual function, but we don't want to use it, then only one cover method:

Public new bool dot () {};

This will completely block the impact of the original class function.

When you visit, you only use base.driver () and base.dot () to access.

Obviously, the keyword this is to use for the current type of visit.

V. Abstrans and interfaces:

Abstract methods can be defined in an abstract class. Keywords: abstract

6. Conversion between object types

Seven, packing and unbox

Packing is used to describe the process of converting value types into a reference type.

The inverse process of converting the reference type is called the inverse process of the value type.

Eight, user-defined conversion

转载请注明原文地址:https://www.9cbs.com/read-117173.html

New Post(0)