How to use VB. NET namespace

Source: Internet
Author: User

When developers want to place their classes in the specified. Net namespace, they need to use namespace.

Namespace

By default, every VB. NET applicationProgramIn a default namespace, this namespace is often referenced as an absolute namespace location of the application. Visual Studio. Net sets it to the top-level namespace and automatically assigns it a name that matches your project name.

When you create a new windowsapplication1 project (the default name is used when you create a new project for the Windows Application in Visual Studio. NET), The namespace of windowsapplication1 is set. To modify the project namespace, open the Project Properties window and modify the rootnamespace field in the application tag. If you want to set a namespace for an existing namespace, for example. windows. if you set namespace for forms, make sure that the class name does not conflict with other class names defined in the namespace.

Naming Conventions

When a. NET application (exe) is generated, the name you select for namespace is not very important, because namespace only exists in your program. The namespace of both windowsapplication1 applications does not conflict with each other. If you generate.. net library (DLL), it will be allocated to people outside your team or organization. At this time, make sure that the namespace you select does not conflict with other namespaces.

For namespace naming conventions, Microsoft generally recommends that you use names related to your company's product names.

Configuration

In addition to absolute positions, you can use relative namespace to place your class in a larger absolute namespace. When you add a class to the project, it appears in the absolute namespace position.

Class class1

End Class

If your project uses windowsapplication1 as its absolute namespace, this class will appear in the name of windowsapplication1.class1.

In relative positions, you can insert a new namespace between the absolute position and the class:

Namespace generalapplications

Class class1

End Class

End namespace

In this case, the complete reference of class1 is windowsapplication1.generalapplications. class1.

Keywords

The namespace keyword may contain the names of multiple namespaces in different periods. Another thing to remember is that namespace may also be nested.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.