In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to use the Imports sentence in VB.NET. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
For beginners, the understanding of VB.NET Imports statements may not be very deep. You can make a detailed interpretation of this through the introduction of this article, and deepen your understanding of the VB.NET language, so as to improve your actual programming efficiency.
Import namespaces or programming elements defined in referenced projects and assemblies. In addition, import namespaces or elements defined in the same project.
Imports [aliasname =]
Namespace
-or-
Imports [aliasname =]
Namespace.element
Each part explains the aliasname
Optional. Import alias or name by which the code can reference the namespace instead of a fully qualified string.
Namespace
Must be chosen. The fully restricted name of the imported namespace. Can be a string nested to any level of namespace.
Element
Optional. The name of the programming element declared in the namespace. Can be any container element.
Remarks
Each source file can contain any number of Imports statements. These statements must come after any option declaration, such as the Option Strict statement, and before any programming element declaration, such as the Module or Class statement.
Imports can only be used at the file level. This means that the declaration context of the import must be a source file, not a namespace, class, structure, module, interface, procedure, or block.
Importing aliases is useful when you need to use a project with the same name declared in one or more namespaces.
Note that the Imports statement does not provide elements from other projects and assemblies for your project to use. The import does not replace the settings for references, it just removes the need to qualify names that are already available for the project.
Rules
Alias. Members should not be declared at the module level with the same name as aliasname. If you do so, the Visual Basic compiler uses aliasname only for declared members and no longer recognizes them as import aliases.
Namespace name. You can provide a single namespace name or a string of nested namespaces. Each nested namespace passes through a period (.) Separated from the next higher-level namespace, as described in the following example.
Imports System.Collections.Generic
Element type. If element is provided, it must represent a "container element", which can contain programming elements for other elements. Container elements include classes, structures, modules, interfaces, and enumerations.
The scope of behavior. The range of elements provided by the Imports statement depends on whether element is specified. If only namespace is specified, all members with * * names in that namespace and members of container elements in that namespace can be used without qualification. If both namespace and element are specified, only the members of the element can be used without qualification.
Limit. Code outside a namespace or container element must usually qualify the name of a member with the name of that namespace or container element. Unless your project wants to access another member with the same name, such qualification will not be necessary after using the Imports statement. In this case, you can specify an aliasname in each Imports statement. You can then qualify members with the same name simply by importing aliases.
Example
The following example imports the Microsoft.VisualBasic.Strings class and assigns it an alias str, which can be used to access the Left method.
'Place Imports statements at
The top of your program.
Imports str = Microsoft.
VisualBasic.Strings
Visual Basic
Class testClass1
Sub showHello ()
'Display only the word "Hello"
MsgBox (str.Left ("Hello World", 5))
End Sub
End Class
Note that the previous example imports a nested namespace, Strings in VisualBasic within Microsoft. The MsgBox function (Visual Basic) accesses the Left method and can use the alias str instead of the entire qualified string.
This is the end of the article on "how to use Imports sentences in VB.NET". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.