The namespaces are used in C# that contains collection of classes. There four types of namespaces in C#.

  1. Directive
  2. Station
  3. Alias
  4. Nested

Directive Namespace:

The directive namespace that is from link library and direct as link.

Eg:

using system.IO

using System;

Console.WriteLine(“Hai”);

Console.WriteLine(“Hello C# Corner!”);

Station Namespace:

The namespace that created automatically for project.

Eg: Console app create.

 using System.Xml;    //creating xml document automatically xml namespace will be added.
XmlDocument objXMLDoc = new XmlDocument();

Alias Namespace:

The user defined name is created.

Eg:

using xx system.IO;
using System;
using hpy = System.Text.StringBuilder; //Alias namespace
class Program
{
    static void Main()
    {
     hpy Happy = new hpy();
     hpy.Append(“smile”);
     hpy.Append(100);
        Console.WriteLine(Happy);
    }
}

Nested Namespace:

This nested namespace hasa  namespace within another namespace.

Eg:

  1. Namespace Humanbeing
  2. {
  3.     Class male
  4.     {
  5.         class female
  6.         {
  7.         }
  8.     }
  9.     namespace animal
  10.     {
  11.         class monkey
  12.         {
  13.         }
  14.     }
  15. }
Advertisements