Close

Patrón Singleton en C#

Ejemplo de clase en c#

public class Singleton
{
   private static Singleton instance = null;
 
   protected Singleton() {}
 
   public static Singleton GetInstance
   {
     get
     {
        if (instance == null)
           instance = new Singleton();
 
        return instance;
     }
   }
}

Para usar nuestro objeto singleton tenemos que llamar al método GetInstance

var mySingleton = Singleton.GetInstance();

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2024 vladymix | WordPress Theme: Annina Free by CrestaProject.