Advertisement
Guest User

Untitled

a guest
Jun 26th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.52 KB | None | 0 0
  1. //se la classe non verrà mai estesa è corretto chiamarla come sealed, altrimenti il singleton può essere utile anche attraverso l'ereditarietà
  2. class Singleton
  3. {
  4.     //istanza corrente
  5.     private static Singleton Instance = null;
  6.     //metodo di ritorno singola istanza
  7.     public static Singleton GetInstance()
  8.     {
  9.         if(Singleton.Instance == null)
  10.             Singleton.Instance = new Singleton();
  11.         return Singleton.Instance;
  12.     }
  13.     //costruttore privato per inibire l'instanziazione al di fuori della classe
  14.     private Singleton()
  15.     {}
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement