Nested Namespaces - CSharp Custom Type

CSharp examples for Custom Type:namespace

Introduction

You can define one namespace inside another namespace.

namespace namespace_name1 {
   namespace namespace_name2 {
   }
}

To access members of nested namespace, use the dot (.) operator as follows.

Demo Code

using System;/*from w  w  w .java2 s. c o  m*/
using n1;
using n1.n2;
namespace n1 {
   class abc {
      public void func() {
         Console.WriteLine("Inside n1");
      }
   }
   namespace n2 {
      class efg {
         public void func() {
            Console.WriteLine("Inside n2");
         }
      }
   }
}
class TestClass {
   static void Main(string[] args) {
      abc fc = new abc();
      efg sc = new efg();
      fc.func();
      sc.func();
   }
}

Result


Related Tutorials