Custom Search Tailored for Microsoft .NET  
Aspexception.com Skip Navigation Links
Error RepositoryExpand Error Repository
.NET ResourcesExpand .NET Resources
About
Skip Navigation LinksHome > .NET Resources > How to tips... > Using Namespaces
How to Declare Namespace in .NET

Understanding Assemblies and Namespaces in .NET

Microsoft .NET provides several ways to think of your code as more than just a bunch of disconnected lines.
  • An assembly provides a fundamental unit of physical code grouping.
  • A namespace provides a fundamental unit of logical code grouping.

Assemblies

An assembly is a collection of types and resources that forms a logical unit of functionality. All types in the .NET Framework must exist in assemblies; the common language runtime does not support types outside of assemblies.

Namespaces

Namespaces are not a replacement for assemblies, but a second organizational method that complements assemblies. Namespaces are a way of grouping type names and reducing the chance of name collisions. A namespace can contain both other namespaces and types. The full name of a type includes the combination of namespaces that contain that type.

Namespace Hierarchy and Fully-Qualified Names

.NET Framework Class Library is organized as hierarchical structure. For instance, the Gridview type is contained in System.Web.UI.WebControls. The namespace hierarchy of Gridview is shown in the following figure.
.Net namespace hierarchy

Declaring namespaces

You can use the namespace statement to declare a namespace in your own code.
namespace MyCompany
{
    public class MyClass
    {
        public MyClass()
        {
            //
            // TODO: Add constructor logic here
            //
        }
    }
}
In the C#, you can use the fully-qualified name for this class such as: MyCompany.MyClass
Site Map  Copyright © Aspexception.com 2008. All rights Reserved. Terms of Use