Article
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    APIs
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog

Home >> .NET >> Namespace in dot Net
Namespace in dot Net
Namespace in dot Net


by Haider M Rizvi on 7/27/2010 5:30:15 PM

Views: 966       Comments: 0

Namespace

Namespaces are program elements designed to help us organize our programs. They also provide assistance in avoiding name clashes between two sets of code. Implementing Namespaces in our own code is a good habit because it is likely to save us from problems later when we want to reuse some of our code. For example, if we create a class named Console, we would need to put it in our own namespace to ensure that there wasn't any confusion about when the System.Console class should be used or when our class should be used.

Example

// Namespace Declaration
using System;

namespace newnamespace
{
    // Program start class
    class space
    {
        public static void Main()
        {
            // Write to console
            Console.WriteLine("This is the new Namespace."); 
        }
    }
}

In the example above we have declared the new namespace by putting the word namespace in front of newnamespace.  Curly braces surround the members inside the newnamespace namespace.

Nested Namespace

// Namespace Declaration
using System;

namespace newnamespace
{
    namespace first
    {       
        class space
        {           
            public static void Main()
            {
                // Write to console
                Console.WriteLine("This is the new first Namespace.");
            }
        }
    }
}

Namespaces allow us to create a system to organize our code. A good way to organize our namespaces is via a hierarchical system. We put the more general names at the top of the hierarchy and get more specific as we go down. This hierarchical system can be represented by nested namespaces. The code above shows how to create a nested namespace.

 

Report Abuse Form
Reason:    
 

Title :
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
     
 
Latest Article by Haider M RizviRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 2659
Advertisement
MindStick SurveyManager
Advertise with Us
  
Copyright © 2013MindStick. All Rights Reserved.