What is Namespace in C# .Net

Last Reply on May 14, 2013 02:18 AM By Ameliamoll

Posted on May 13, 2013 04:36 AM

please tell me any one .how to use of namespace .

Posted on May 13, 2013 05:01 AM

Hi Prashant,

The name space is nothing but logical separation of the code. In other word It is grouping of the classes.., under a name the name is called NameSpace.

Example:

namespace Test
{
    public class Class1
    {
    }
}

Here the Class1 is contained within namespace so called Test

namespace Test
{
    public class Class2
    {
    }
}

Now Class2 is also in the same NameSpace. We cannot declare two classes with same name in same name space but it can be done while namespance is different.

More.., When you are using once class object or its feature in another class in different namespace, you need to get this calss available by using that namespace like

namespace Test3
{
    using Test;

    public class Class3
    {
        Class1 class1 = new Class1();
    }
}

Thanks and Regards,

Rk_Hirpara.


Posted on May 14, 2013 02:18 AM

Namespaces are a way of organizing vast number of classes,structures,enumerations,delegates and interfaces that .NET Framework class library provides.Namespaces are hierarchially structured index into a class library, which is available to all of .NET languages.The namespaces, or object references are typically organized by function.

 Have a look at http://msdn2.microsoft.com/en-us/library/k50ex0x9