ASP.NET
  Home arrow ASP.NET arrow Page 4 - Introduction to ASP.NET
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 
Mobile Linux 
App Generation ROI 
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? 
ASP.NET

Introduction to ASP.NET
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 33
    2004-08-24

    Table of Contents:
  • Introduction to ASP.NET
  • The .NET Framework Class Library (FCL)
  • The Common Language Infrastructure (CLI)
  • Namespaces
  • Assemblies
  • Object Orientation in the .NET Platform
  • OO Is at the Heart of Every ASP.NET Page
  • Porting an Existing Application to ASP.NET
  • New Features in ASP.NET
  • New Features in ASP.NET v1.1

  • 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


    Introduction to ASP.NET - Namespaces


    (Page 4 of 10 )

    Namespaces, a key part of the .NET Framework, provide scope to both preinstalled framework classes and custom-developed classes. Namespaces are declared for a given set of classes (types) by enclosing those classes in one of the following declarations:

    // C#
    namespace myNamespace
    {
      class myClass
      {
        // class implementation code
      }
    }

    ' VB.NET
    Namespace myNamespace
      Class myCls
        ' class implementation code
      End Class
    End Namespace

    Namespaces may also be nested, as shown here:

    ' VB.NET
    Namespace myFirstNamespace
      Public Class myCls
        ' class implementation code
      End Class
      Namespace mySecondNamespace
        Public Class myCls
         ' class implementation code
      End Class
      Public Class myCls2
        ' class implementation code
      End Class
     End Namespace
    End Namespace

    This code is perfectly valid because we’ve declared the second myCls in the nested namespace mySecondNamespace. If we tried to declare two identically named classes within the same namespace, we would get a compiler error informing us that there was a naming conflict, because each class name must be unique within its namespace. To use the classes we just declared, we can do something like the following:

    ' VB.NET
    Imports System
    Imports myFirstNamespace
    Imports myFirstNamespace.mySecondNamespace

    Module namespaces_client_vb

    Sub Main()
      Dim newClass As New myFirstNamespace.myCls
      Dim newClass2 As New myCls2 Console.WriteLine("Object creation  succeeded!")
    End Sub

    End Module

    We use the Imports keyword in Visual Basic .NET to enable the use of member names from these namespaces without explicitly using the namespace name. However, because we used the class name myCls in both the myFirstNamespace and mySecondNamespace namespaces, we need to use the fully qualified name for this class, while we are able to instantiate myCls2 with only the class name. We can just as easily use these classes from C#, as shown here:

    using System;
    using myFirstNamespace;
    using myFirstNamespace.mySecondNamespace;

    class namespaces_client

    {
       public static void Main()
      {
      myFirstNamespace.myCls newClass = new myFirstNamespace.myCls();
      myCls2 newClass2 = new myCls2();
      Console.WriteLine("Object creation succeeded!");
     }
    }

    C# uses the using keyword for importing namespaces. Notice that in both cases, in addition to importing the namespaces we defined, we’ve also imported the System namespace. This is what allows us to use the Console class defined in the System namespace to write to a console window without referring explicitly to System.Console.

    Classes that are part of the .NET Framework are organized by functionality into namespaces that make them easier to locate and use. All classes that are a part of the .NET Framework begin with either “System” or “Microsoft.” Examples include:

    System -- Contains all the .NET primitive data types as well as utility classes such as Console and Math that are apt to be widely used in .NET applications.

    System.Collections -- Contains classes used to implement various kinds of collections in .NET, including ArrayList, Dictionary, and Hashtable.

    System.Data -- Contains classes used to access and manipulate data, as well as child namespaces such as System.Data.SqlClient, which contain data access classes specific to a particular data provider.

    System.Web -- Contains classes used to process web requests, as well as child namespaces such as System.Web.UI, which contains such classes as the Page class, the basis for all ASP.NET pages.

    Buy the book!If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!

    Visit the O'Reilly Network http://www.oreillynet.com for more online content.

    More ASP.NET Articles
    More By O'Reilly Media


       · I don't understand...
     

    ASP.NET ARTICLES

    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ





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