Developing Namespaces in VB.NET 2005 - A simple example of a namespace
(Page 2 of 6 )
In my previous article (“Inheritance in VB.NET 2005”), I declared three classes, namely “First,” “Second” and “Third.” I shall use the same solution and further extend it with examples of “namespaces.”
The simplest construction of a namespace would be as follows:
NamespaceNamespace1
EndNamespace
Every namespace should start with the keyword “Namespace” followed by the name of the namespace (in this case, it is “Namespace1”). It is always recommended to name the namespace in a meaningful manner to identify a group of classes.
To the same solution, add a new class file named “Namespace1_First.vb” and modify the code as follows:
NamespaceNamespace1
Public Class First
Private m_a As Integer
Private m_b As Integer
Public Sub New(ByVal x As Integer, ByVal y As Integer)
m_a = x
m_b = y
End Sub
Public Property A() As Integer
Get
Return m_a
End Get
Set(ByVal value As Integer)
m_a = value
End Set
End Property
Public Property B() As Integer
Get
Return m_b
End Get
Set(ByVal value As Integer)
m_b = value
End Set
End Property
End Class
EndNamespace
The next section will give you the explanation and sample code to activate the example shown above.
Next: Accessing a class available in a namespace >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee