Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- sealed class Singleton {
- private static readonly Singleton instance = new Singleton();
- private Singleton() {
- }
- static Singleton() {
- }
- public static Singleton Instance {
- get {
- return instance;
- }
- }
- }
- */
- public class Singleton<T> where T : class, new()
- {
- private static readonly object syncLock = new object();
- private static T instance;
- protected Singleton()
- {
- }
- public static T Instance
- {
- get
- {
- if (instance == null)
- {
- lock (syncLock)
- {
- if (instance == null)
- {
- instance = new T();
- }
- }
- }
- return instance;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement