Singleton Pattern : Singleton Pattern : Design Patterns C# Examples


C# Examples » Design Patterns » Singleton Pattern »

 

Singleton Pattern









    
using  System;

public  class  SingletonClass
{
        private  static  SingletonClass  instance;

        static  SingletonClass()
        {
                instance  =  new  SingletonClass();
        }

        private  SingletonClass()  {  }

        public  static  SingletonClass  Instance
        {
                get  {  return  instance;  }
        }

        public  void  SomeMethod1()  {  }
        public  void  SomeMethod2()  {  }
}

public  class  MainClass
{
        public  static  void  Main()
        {
                SingletonClass  s  =  SingletonClass.Instance;
                s.SomeMethod1();

                SingletonClass.Instance.SomeMethod2();

        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Design Patterns
» Singleton Pattern