Accessibility

xiaoxiao2021-03-06  49

"Accessibility" of the declared elements is the ability to use this element; that is, the code reads the elements or the permissions of the write element. This not only depends on the way the elements itself depends on the accessibility of the element container. If the element contains irrevoiled, all elements it contains is irreparable, even the elements that have been declared as public. For example, the public variable in the Private structure can be accessed from the class included in the class, and cannot be accessed from the class.

Public

The elements in the PUBLIC keyword declared in the DIM statement can be accessed from the following position: any location in the same item, reference to other items of the project, and the assembly generated by the project. The following code shows example public declaration:

Public Class ClassForeveryBody

You can only use public in modules, namespaces, or file levels. This means that the public element can be declared in the source file or in the module, class, or structure (but not in the process).

Protected

The protected keyword declaration element in the DIM statement can only be accessed from the same class, or in the derived class of the class. The following code shows the sample protected statement:

Protected Class ClassFormyHeirs

Protected can only be used when the class is only used as a member of the statement.

Friend

The Friend keyword declaration element in the DIM statement can be accessed from the same project, but cannot be accessed from the project. The following code shows example Friend declaration:

Friend StringforthisProject As String

You can only use Friend in modules, namespaces, or file levels. This means that the Friend element can be declared in the source file or within the module, class, or structure (but cannot be in the process).

Protected Friend

The Friend keyword and protected keywords in the DIM statement declare elements can be accessed from the derived class or the same item or both. The following code shows the sample protected friend declaration:

Protected Friend StringForProjectandHeirs As String

Protected Friend can only be used when the class is class and only when a member of the declaration class.

Private

The private keyword declaration element in the DIM statement can only be accessed from the same module, class or structure. The following code shows example private declaration:

Private NumberformeOnly as in

Only use private in modules, namespaces, or file levels. This means that the private element can be declared in the source file or in the module, class, or structure (but not in the process).

Note that in the module level, there is no accessibility keyword

DIM statement

PRIVATE declaration is equivalent. However, it may be desirable to use

The private keyword makes the code easier to read and explain.

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

New Post(0)