What is Namespace and where it is used in C# .Net

Last Reply on Jul 03, 2013 02:11 AM By RkHirpara

Posted on Jul 02, 2013 05:09 AM

what is namespace. what are the use of namespace in c#. can any please explain the example of namespace in detail

Posted on Jul 03, 2013 02:11 AM

Hi,

namespaces are used to group code, likes Flats grouped in Floor, Floors are Grouped into the Wing and wings are Grouped into Apartment and so forth.

Now there might be multiple Flat no. 304, so you can specify the wing like C/304, so it will point to the Flat No. 304 of C-Wing only.

Likewise you may group classes and Interfaces into a group colled namespace, so you can qualify class name by namespace using, namespace name as per example above.

Now namespaces, Classes and Interfaces collectively too can grouped as namespace. while you are coding and using any class beyond the namespace of your current class you can make that class available by means of namespace in which its contained. as I explained in my previous answer in link below

  1. What is Namespace in C# .Net

You can also access the class without using "using" by namespace name like

Test.Class1 classObj = new Test.Class1();

Here test is namespace name and Class1 is name of class, as per content of the link aboce.

Besides this yet another benifit is you may have same class name in different namespaces.

Thanks and Regards,

Rk_Hirpara