Namespaces prevent name conflicts : Namespace : Language Basics C# Examples


C# Examples » Language Basics » Namespace »

 

Namespaces prevent name conflicts









    
using  System;    
    
namespace  Counter  {    
    class  MyClass  {    
        public  MyClass(){
            Console.WriteLine("Counter1  namespace.");  
        }
    }    
}    
  
namespace  Counter2  {    
    class  MyClass  {  
        public  MyClass()  {  
            Console.WriteLine("Counter2  namespace.");  
        }  
    }  
}  
  
class  MainClass  {    
    public  static  void  Main()  {    
        //  This  is  CountDown  in  the  Counter  namespace.  
        Counter.MyClass  m1  =  new  Counter.MyClass();    
  
        //  This  is  CountDown  in  the  default  namespace.  
        Counter2.MyClass  m2  =  new  Counter2.MyClass();  
  
    }    
}
    
   
  
   



Output

Counter1 namespace.
Counter2 namespace.


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Namespace