Creating and Using Namespaces in visual basic.Net
Namespaces help you to create logical groups of related classes and interfaces.

How do you implement namespaces in a database application? What are the benefits of using namespaces in a database application? For all this read Database programming using visual basic, c# (c sharp) sql server.
For example, we create a new class named TextBox to accept only an integer type of value. However, if we want to use the VS.Net TextBox control in the same project, there will be a conflict in the name. When we create a Namespace, we will be able to easily distinguish between the Class TextBox created by us and the one provided by VS.Net.
So, we need to change the MyProject to the name which we wish. We will name the project as Acct1.
We can also organize classes using the Namespace keyword.
For example, you can create a user-defined namespace called EmpNamespace in the project called Acct1 and place the class EmpClass within the EmpNamespace block.
Namespace EmpNamespace
Class EmpClass
End Class
End Namespace
The fully qualified or proper usage of the class EmpClass will be:
Acct1.EmpNamespace.EmpClass
The .Net framework uses a dot(.) as a delimiter between classes and namespaces.
Direct addressing involves directly accessing any class in the namespace by providing the fully qualified name.
Example of using fully qualified name is given below:
Microsoft.VisualBasic.MsgBox("Using Fully Qualified Name")
If we want to make all the classes in a given namespace available without the need to type the entire namespace each time, you can use the Imports statement. An example of using the Imports statement is given below:
Imports Microsoft.VisualBasic
...
MsgBox("Using Imports Statement")
Similarly, in the example we have chosen:
Imports Acct1.EmpNameSpace
Namespaces are of two types, Local and Global. Local Namespaces are accessible only to the applications to which they belong. Global Namespaces are accessible from all applications.
Summary:
In this article we have learnt the need for a NameSpace, created one and used it in an example.
More on Namespaces - namespace examples
Need for Namespace
NameSpaces allow us to organize Classes so that they can be easily accessed in other applications. Namespaces enable us to avoid any naming conflicts between classes that have the same name. We can use two classes with the same name in an application provided they belong to different namespaces.
How do you implement namespaces in a database application? What are the benefits of using namespaces in a database application? For all this read Database programming using visual basic, c# (c sharp) sql server.
For example, we create a new class named TextBox to accept only an integer type of value. However, if we want to use the VS.Net TextBox control in the same project, there will be a conflict in the name. When we create a Namespace, we will be able to easily distinguish between the Class TextBox created by us and the one provided by VS.Net.
Creating Namespaces in visual basic.Net
Every project in Visual Basic.Net has a root namespace, which is set in the Property page of the project. When we create a project, by default, the name of the root namespace for the project is set to the name of the new project. For example, the root namespace for a project named MyProject is MyProject. Usually, when we create a project, we would like to give it a name which we like.So, we need to change the MyProject to the name which we wish. We will name the project as Acct1.
We can also organize classes using the Namespace keyword.
For example, you can create a user-defined namespace called EmpNamespace in the project called Acct1 and place the class EmpClass within the EmpNamespace block.
Namespace EmpNamespace
Class EmpClass
End Class
End Namespace
The fully qualified or proper usage of the class EmpClass will be:
Acct1.EmpNamespace.EmpClass
The .Net framework uses a dot(.) as a delimiter between classes and namespaces.

Using Namespaces in visual basic.Net
We have created a Namespace in the previous step. Now, we will use the Namespace explicitly through direct addressing or implicitly through the Imports statement.Direct addressing involves directly accessing any class in the namespace by providing the fully qualified name.
Example of using fully qualified name is given below:
Microsoft.VisualBasic.MsgBox("Using Fully Qualified Name")
If we want to make all the classes in a given namespace available without the need to type the entire namespace each time, you can use the Imports statement. An example of using the Imports statement is given below:
Imports Microsoft.VisualBasic
...
MsgBox("Using Imports Statement")
Similarly, in the example we have chosen:
Imports Acct1.EmpNameSpace
Namespaces are of two types, Local and Global. Local Namespaces are accessible only to the applications to which they belong. Global Namespaces are accessible from all applications.
Summary:
In this article we have learnt the need for a NameSpace, created one and used it in an example.
More on Namespaces - namespace examples
Visual Basic.Net Articles
- Business, Presentation and Data layers
- Implementing Structure in visual basic.Net
- access database in visual basic.net
- user custom controls in C# visual basic 2005, asp.net, application
- Using assemblies in .net applications
- How to create and sign a shared assembly
- Data access using ado .net in Visual Basic .Net
- Middle tier component for accessing sql server using visual basic .net
- Databinding | binding data to a datagrid control
- Data binding | CurrencyManager and BindingContext
- Dataset in Visual basic .net
- Ado.net data access
People also viewed:
Create your own ERP Software using ASP Core>>
Create your own Azure SOM Software>>
Create your own ERP Software using ASP .Net and SQL>>
Create your own Accounting Software using C# >>
Create your own SOM using Entity Framework MVC >>





Most Viewed
Azure Q & A
Azure Platform
Grid-View
GridView CommandField example
Details-View
GridView and DetailsView Master/Detail page using SqlDataSource control
POCO
POCO overview and advantages - POCO class, Entity Framework in Enterprise Applications
Entity Framework
Query entity data model using linq to entities
Array List
Difference between arraylist and list collection
Web Services
How to create a Web service using Visual Studio.net
Form-View
FormView DataBound Event
Object Oriented Programming
Calling base class constructor in C#
Linq
Convert a sequence to a generic list using ToList()method
Project Ideas
Project ideas for students
AccountingSoftware
Accounting Software
MVC
Creating an ASP.Net MVC 3 application
.Net
Using assemblies in .net applications
ASP .Net
How to implement form validation using ASP.Net 2.0 Validation Controls