Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the concepts of various VB.NET access levels

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about how to understand the concept of various VB. NET access levels. Many people may not understand it. In order to let everyone know more, Xiaobian summarizes the following contents for everyone. I hope everyone can gain something according to this article.

VB. NET programming language and Java complaint mechanism is roughly the same, which also includes many access levels, so that we can improve the security of program development. The "access level" of a declared element refers to the extent to which it can be accessed, that is, what code has read or write permissions on it. This depends not only on how the element itself is declared, but also on the access level of the element container. Code that contains an element cannot access any elements contained within that element, even those declared Public. For example, a Public variable in a Private struct can be accessed from inside the class containing the struct, but not from outside the class.

Public

The Public (Visual Basic) keyword in a declaration statement indicates that an element can be accessed from code anywhere in the same project, from other projects that reference the project, and from any assemblies generated by the project. The following code shows an example of a Public declaration.

Public Class ClassForEverybody Public can only be used at the module, interface, or namespace level. This means that a public element can be declared at the source file level or namespace level, or inside an interface, module, class, or struct, but not inside a procedure.

Protected

The Protected (Visual Basic) keyword in a declaration statement indicates that elements can only be accessed from within the same class or from classes derived from that class. The following code shows an example of a Protected declaration.

Protected ClassForMyHeirs can only be used when declaring members of a class and only at the class level. This means that a protected element can be declared in a class, but not at the source file or namespace level, or inside an interface, module, struct, or procedure.

Friend

The Friend (Visual Basic) keyword in a declaration statement indicates that elements can be accessed from within the same assembly, but not from outside the assembly. The following code shows an example of a Friend declaration.

Friend stringForThisProject As String Friend can only be used at the module, interface, or namespace level. This means that you can declare a friend element at the source file level or namespace level, or inside an interface, module, class, or struct, but not inside a procedure.

Protected Friend

When the Protected and Friend keywords appear together in a declaration statement, they indicate that the element can be accessed from a derived class, within the same assembly, or both. The following code shows an example ProtectedFriend declaration.

Protected Friend stringForProjectAndHeirs As String ProtectedFriend can only be used when declaring members of a class and only at the class level. This means that the protected friend element can be declared in a class, but not at the source file level or namespace level, or within an interface, module, struct, or procedure.

Private

The Private (Visual Basic) keyword in a declaration statement indicates that an element can only be accessed from within the same module, class, or struct. The following code shows an example of a Private declaration.

Private numberForMeOnly As Integer Private can only be used at the module level. This means that a private element can be declared inside a module, class, or struct, but not at the source file or namespace level, inside an interface, or inside a procedure.

At the module level, a Dim statement without any access-level keywords is equivalent to a Private declaration. However, you may want to use the Private keyword to make the code easier to read and interpret.

After reading the above, do you have any further understanding of how to understand the concept of various VB. NET access levels? If you still want to know more knowledge or related content, please pay attention to the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report