A namespace is a method of organizing a group of
assemblies, classes, or types. A namespace acts as a container—like a disk folder—for
classes organized into groups usually based on functionality.
Namespaces are heavily used in C# programming in two
ways. First, the .NET Framework uses namespaces to organize its many classes,
as follows:
System.Console.WriteLine("Hello World!");
System is
a namespace and Console is a class in that namespace.
The using keyword can be used so that the complete
name is not required, as in the following example:
using System;
Console.WriteLine("Hello");
Console.WriteLine("World!");
Second, declaring your own namespaces can help you
control the scope of class and method names in larger programming projects. Use
the namespace keyword to declare a namespace, as in the following example:
namespace SampleNamespace
{
class SampleClass
{
public void SampleMethod()
{
System.Console.WriteLine(
"SampleMethod inside SampleNamespace");
}
}
}
·
They
organize large code projects.
·
They
are delimited by using the . Operator.
·
The
using directive obviates the requirement to specify
the name of the namespace for every class.
·
The
global namespace is the "root" namespace: global::System will always refer to the .NET Framework
namespace System.
The
following is list of some important and frequently used .NET namespaces:
·
System.Collections
·
System.Data
·
System.Diagnostics
·
System.Drawing
·
System.IO
·
System.Net
·
System.Reflection
·
System.Runtime
·
System.Security
·
System.Threading
·
System.Web
·
System.Windows.Forms
·
System.Xml
A
C# namespace is the equivalent of a Java language package.
No comments:
Post a Comment