Namespaces in C#

Chapter 3

INTRODUCTION TO NAMESPACES

We had discussed earlier regarding namespaces , here we will discuss about the same in detail.

Knowingly or unknowingly , if you have been working with C# , you have been using namespaces, for example, we had written a line of code  using System;   here System is a namespace. this namespace is predefine in the .NET library and contains enormous classes that help is making your program work and reducing the amount of code to be written by you.

Basically Namespaces help us in organising our code, and hence avoiding nameclashes. for example, lets say you create a class named String, you do not want the compiler to confuse with the "System.String" class defined inside the System namespace( yes String is a class). hence you define the class in your own namespace for example "Logiphix", hence you can access both the string classes using the different namespaces.

For example.
You can use the "System.String" class as well as the newly defined class as "Logiphix.String"

By now you must have understood the use of namespaces in your code.

No comments:

Post a Comment