Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - Developing Namespaces in VB.NET 2005
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Developing Namespaces in VB.NET 2005
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 8
    2006-09-11

    Table of Contents:
  • Developing Namespaces in VB.NET 2005
  • A simple example of a namespace
  • Accessing a class available in a namespace
  • A namespace with more than one class
  • A simple example for a nested namespace
  • Summary

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Developing Namespaces in VB.NET 2005 - A namespace with more than one class


    (Page 4 of 6 )

    In the previous section, I dealt with only one class in the namespace.  Now, let us add one more class file named “Namespace1_second.vb” and modify the code as follows:

    NamespaceNamespace1
        Public Class Second
            Inherits First
            Private m_c As Integer
            Public Sub New(ByVal x As Integer, ByVal y As Integer,
    ByVal z As Integer)
                MyBase.New(x, y)
                m_c = z
            End Sub
            Public Property C() As Integer
                Get
                    Return m_c
                End Get
                Set(ByVal value As Integer)
                    m_c = value
                End Set
            End Property
            Public Function getSum() As Integer
                Dim s As Integer
                s = Me.A + Me.B + Me.C
                Return s
            End Function
        End Class
    EndNamespace

    The above code contains only one class “Second” in the namespace “Namespace1.” But, from the point of view of our Visual Studio solution, we have two classes, “First” and “Second,” in the same namespace, “Namespace1.” The important point here to remember is that “classes in several files may also belong to the same namespace based on the declarations.” 

    If you prefer to embed several classes in the same namespace within the same file, it is still possible with the following type of construct:

    NamespaceNamespace1
        Public Class First
          .
          .
          .
        End Class
        Public Class Second
            Inherits First
          .
          .
          .
        End Class
    EndNamespace

    We need to modify the code in the form as follows to access the class “second” available in the namespace “Namespace1”:

    PublicClass Form1
        Private Sub Button1_Click(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles Button1.Click
            Dim obj As New Namespace1.Second(10, 20, 30)
            Me.Label1.Text = obj.getSum
        End Sub
    EndClass

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · Hello guys! Expand your knowledge of OOPS to namespaces. thanks and bye
     

    VISUAL BASIC.NET ARTICLES

    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET (F...
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway