Namespaces can be nested : NameSpace : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » NameSpace »

 

Namespaces can be nested









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Namespaces can be nested. 
 
using System; 
 
namespace NS1 { 
  class ClassA { 
     public ClassA() { 
       Console.WriteLine("constructing ClassA"); 
    } 
  } 
  namespace NS2 { // a nested namespace 
    class ClassB { 
       public ClassB() { 
         Console.WriteLine("constructing ClassB"); 
      } 
    } 
  } 
} 
 
public class NestedNSDemo { 
  public static void Main() { 
    NS1.ClassA a= new NS1.ClassA(); 
 
 // NS2.ClassB b = new NS2.ClassB(); // Error!!! NS2 is not in view 
 
    NS1.NS2.ClassB b = new NS1.NS2.ClassB(); // this is right 
  } 
}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» NameSpace