---
title: "Namespace"  
description: "In this article i am going to show what is namespace in c# program"  
author: "Niraj Kumar Mishra"  
published: 2017-08-25  
updated: 2019-08-19  
canonical: https://www.mindstick.com/articles/12552/namespace  
category: "c#"  
tags: ["c#", "oops"]  
reading_time: 2 minutes  

---

# Namespace

##### Need for Namespaces:

[Namespaces](https://www.mindstick.com/forum/155583/what-are-namespaces-in-c-sharp) allow us to create a system to [organize your](https://answers.mindstick.com/qa/50491/how-to-organize-your-ibooks-library-on-iphone-x) code. You can create namespaces via a hierarchical is good way to organize [your code](https://www.mindstick.com/forum/157976/how-can-you-use-jquery-s-testing-framework-such-as-qunit-to-write-unit-tests-for-your-code). You can also create a [nested](https://www.mindstick.com/forum/45/itemcommand-event-in-nested-repeater-and-listview) [namespace](https://www.mindstick.com/articles/28/namespace-in-dot-net) by placing code in different sub-namespaces, you can keep your code [organized](https://yourviews.mindstick.com/story/4668/regions-rivers-where-kumbha-mela-is-organized) .

##### Example:

```
namespace xyz.csharp.namespaces
{
    public class Demo
    {
        public string Message()
        {
            return "Hello, world";
        }
    }
}
```

Namespaces are hierarchical, and the name xyz.[csharp](https://www.mindstick.com/forum/226/how-to-get-application-directory-using-c-sharp-csharp).namespaces is actually shorthand for defining a namespace you can also make that namespace in this order:\

```
namespace xyz
{
 namespace csharp
  {
    namespace namespaces
    {
      public string Message()
      {
        return "Hello, world";
      }
    }
  }
}
```

##### Using alias directives

You can also use using directive as alias .by using alias you don’t need write full

path of namespace in program.

using identifier = namespace-or-type-name ;

##### Example:

```
namespace Namespace1.Namespace2
{
    class abc { }
}
namespace Namespace3
{
    using A = Namespace1.Namespace2;
    class xyz : abc { }
}
```

Here, within member declarations in the Namespace3 namespace, A is an alias for

Namespace1.Namespace2.\

##### Using namespace directives

A using namespace directive imports the types contained in a namespace into the immediately enclosing [compilation](https://www.mindstick.com/interview/358/which-is-the-first-level-of-compilation-in-the-dot-net-languages) unit or namespace body, enabling the identifier of each type to be used without qualification .

```
using-namespace-directive:using namespace-name ;
```

##### Example:

```
namespace Namespace1.Namespace2
{
    class abc { }
}
namespace Namespace3
{
    using Namespace1.Namespace2;
    class xyz : abc { }
}
```

Here, within member declarations in the Namespace3 namespace, the type

members of Namespace1.Namespace2 are directly available, and thus class

Namespace3.B derives from class Namespace1.Namespace2.abc

***\***

---

Original Source: https://www.mindstick.com/articles/12552/namespace

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
