Console Application – Namespaces

C# Namespaces – Console Application

The namespaces helps to organize a programs. A namespace is designed for providing way to keep set of classes in a one organization. Namespace avoiding a clash of class by declaring same class name declared in another namespace.

Declaring Namespace :

A namespace definition starts with keyword namespace followed by the namespace name as like below:

namespace namespace_example
{
//programming code declaration
}

How namespace will helps:
For example in c# console application program, if we created same class name which is already available in .net framework class library, so there is a same class name clash problem occurs, but the namespace helps to avoid this kind of same declaration class name problem.

namespace MyFirstConsoleApp
{
class Program
{
static void Main(string[] args)
{
//code
}
}
}

In above example we defined namespace MyFirstConsoleApp with one class Program and a static function Main.

Here, we understand the same class name problem with an example.

The output of above namespace example is:

namespace in c# console application.

namespace in c# console application.

 


Nested Namespaces :

If we define one namespace inside the other namespace known as nested namespace.
Let’s take an example of nested namespace to understand more..

The output of  above nested namespace example is:

namespace in c# console application.

namespace in c# console application.

Leave a Reply

Your email address will not be published. Required fields are marked *

6 + 5 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">