ASP.NET
  Home arrow ASP.NET arrow Page 3 - Prerequisites For .NET Programming
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
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? 
ASP.NET

Prerequisites For .NET Programming
By: James Yang
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2002-01-06

    Table of Contents:
  • Prerequisites For .NET Programming
  • Object-orientated programming
  • Namespaces
  • Conclusion

  • 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


    Prerequisites For .NET Programming - Namespaces


    (Page 3 of 4 )

    As with C++, namespaces are a vital part of .NET languages. You can think of a namespace as a "virtual container" for classes, functions and variables, which encapsulates them into a uniquely identifiable region. Namespaces separate variables into physical scopes, which reduces variable naming ambiguities. The pseudo code for a namespace is shown below:

    Namespace ns1

    {

    variable x

    Namespace ns2

    {

    variable y

    }

    }


    As you can see, namespaces are hierarchical, meaning that several namespaces can be declared (and used) within a "parent" namespace. To refer to a nested namespace, you need to reference it using its parent Id first, followed by the dot operator ".", and then its actual namespace name.

    For example, if you wanted to refer to the "sqlConnection" class in the "Data" level two namespace (second in the hierarchy) to create a new instance of that object, then you would do so like this:

    System.Data.sqlConnection myConn = new System.Data.sqlConnection();

    See how the dot operator separates each new namespace hierarchy? If we ran this line of C# code, then the "myConn" object would now contain a new instance of the System.Data.sqlConnection class.

    Here is a simple example of using namespaces in both VB.NET and C#:

    VB.NET:

    Namespace Computer

    Class IBM

    'Class methods go here

    End Class

    End Namespace


    C#:

    namespace Computer

    {

    class IBM

    {

    // Class methods go here

    }

    }


    As mentioned above, namespaces can be arranged in a hierarchical format. We can create nested namespaces in both VB.NET and C#:

    VB.NET:

    Namespace Computer

    Namespace Desktop

    Class IBM

    'Class methods go here

    End Class

    End Namespace

    Namespace Server

    Class MainFrame

    Public Function ShowMainFrame

    'Code for function goes here

    End Function

    End Class

    End Namespace

    End Namespace


    C#:

    namespace Computer

    {

    namespace Desktop

    {

    class IBM

    {

    // Class methods go here

    }

    }

    namespace Server

    {

    class MainFrame

    {

    public void ShowMainFrame()

    {

    // Code for function goes here

    }

    }

    }

    }


    Namespaces are very simple to create in both VB.NET and C#. In VB.NET, we use the "Namespace namespace_name ... End Namespace" syntax, while in C#, we use the "namespace namespace_name {}" syntax. As you'll see in future articles, all classes in both VB.NET and C# are encapsulated into namespaces.

    More ASP.NET Articles
    More By James Yang


     

    ASP.NET ARTICLES

    - How Caching Means More Ca-ching, Part 2
    - How Caching Means More Ca-ching, Part 1
    - Reading a Delimited File Using ASP.Net and V...
    - What is .Net and Where is ASP.NET?
    - An Object Driven Interface with .Net
    - Create Your Own Guestbook In ASP.NET
    - HTTP File Download Without User Interaction ...
    - Dynamically Using Methods in ASP.NET
    - Changing the Page Size Interactively in a Da...
    - XML Serialization in ASP.NET
    - Using Objects in ASP.NET: Part 1/2
    - IE Web Controls in VB.NET
    - Class Frameworks in VB .NET
    - Cryptographic Objects in C#: Part 1
    - Sample Chapter: Pure ASP.Net






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT