Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - 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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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 - Accessing a class available in a namespace


    (Page 3 of 6 )

    This section explains the code provided in the previous section and further proceeds with the same.

    From the previous section, you could observe that I included a new class, “First,” within the namespace “Namespace1.”  You should also observe that there exists another “First” class within the same solution.  But it doesn’t display any error because we embedded the newly added class into a “namespace.”  Try removing the namespace construct and you will see an error as the result!

    To work with the above class, I modified the code as follows:

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

    The most important statement from the above is only the following:

            Dim obj As New Namespace1.First(10, 20)

    The above statement creates an object named “obj” based on the class “First” which exists in the namespace “Namespace1.”  That’s the trick to accessing a class available in a namespace.

    For further clarity, let us understand the following two statements:

            Dim obj As New First(10, 20)
            Dim obj As New Namespace1.First(10, 20)

    Both of the above statements look very similar.  At this point, we must be careful enough to understand the difference between the two.  In our solution, I have two classes with the same name, “First.” One is inside the namespace “Namespace1” and the other is outside. The first statement creates the object based on the class “First” which is declared outside “Namespace1.” The second statement creates the object based on the class “First” which is declared inside “Namespace1.”

    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

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - 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...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek