The use of namespace hierarchies : Namespace « Language Basics « C# / CSharp Tutorial






namespace CompanyName
{
  namespace UserInterface  // nested namespace
  {
    public class MyClass
    {
      public void Test()
      {
        System.Console.WriteLine("UserInterface Test()");
      }
    }
  }
}


namespace CompanyName.DatabaseAccess  // nested namespace using dot
{
  public class MyClass
  {
    public void Test()
    {
      System.Console.WriteLine("DatabaseAccess Test()");
    }
  }
}


class MainClass {

  public static void Main() {
    CompanyName.UserInterface.MyClass myUI = new CompanyName.UserInterface.MyClass();
    CompanyName.DatabaseAccess.MyClass myDB = new CompanyName.DatabaseAccess.MyClass();

    CompanyName.DatabaseAccess.MyClass myMT = new CompanyName.DatabaseAccess.MyClass();

    myUI.Test();
    myDB.Test();
    myMT.Test();
  }
}
UserInterface Test()
DatabaseAccess Test()
DatabaseAccess Test()








1.5.Namespace
1.5.1.Namespace Introduction
1.5.2.Full qualify name
1.5.3.Simplest namespace with class definition
1.5.4.Declare a namespace
1.5.5.Demonstrate a namespace.
1.5.6.Use fully qualified class name
1.5.7.Two levels of Namespaces
1.5.8.Namespace with dot
1.5.9.Rename the namespaces
1.5.10.Namespaces prevent name conflicts
1.5.11.Namespaces are additive.
1.5.12.Namespaces can be nested
1.5.13.Demonstrate the :: qualifier.
1.5.14.The use of two namespaces
1.5.15.The use of namespace hierarchies
1.5.16.Creates a namespace with a single class
1.5.17.Same class name under different Namespaces