Namespaces in C#
1. Namespaces:
àNamespaces play an
important role in managing related classes in C#. The .NET Framework uses
namespaces to organize its built-in classes. For example, there are some
built-in namespaces in .NET such as System, System.Linq, System.Web, etc. Each
namespace contains related classes.
àTo use classes under a
namespace without the fully qualified name, import the namespace with the using keyword
at the top of C# class file.
àThe biggest advantage of
using namespace is that the class names which are declared in one namespace
will not clash with the same class names declared in another namespace.
àNamespaces are user defined
as well as system defined in .NET framework.
1. User Define
Namespaces:
Declaring a Namespace
The C# language provides a
keyword namespace followed by the name of the
namespace and curly braces containing the body of the namespace as to
create a user-defined namespace. The general form of declaring a namespace is
as follows.
Syntax:
namespace
<namespace_name>
{
//
Classes/Interfaces/Structs/Enums etc.
}
It is not possible to use
any access specifiers like private, public etc. with a namespace declarations.
The namespaces in C# implicitly have public access and this is not modifiable.
The namespace allows only
public and internal elements as it members. The default is internal.
2.System Define Namespaces:
The following are some of
the standard system defined namespaces in .NET framework.
àSystem:
Contain classes that implement basic functionalities like mathematical
operations, data conversions etc.
àSystem.IO:
Contains classes used for file I/O operations.
System.Net: Contains class
wrappers around underlying network protocols.
àSystem.Collections:
Contains classes that implement collections of objects such as lists, hashtable
etc.
àSystem.Data:
Contains classes that make up ADO.NET data access architecture.
àSystem.Linq:
Contains classes that make up LINQ data access architecture.
àSystem.Threading:
Contains classes that are used for multithreading programming.
àSystem.Web:
Classes that implement HTTP protocol to access web pages.
àSystem.Xml:
Classes that are used for processing XML data.
Comments
Post a Comment