//bad implementation - don't use//also note some initialization etc. is omitted for brevity public static Foo Instance{ get { // This lock allows thread safety. lock (_mutex) { if (_instance == null) _instance = new Foo(); return _instance; } } }
public sealed class singleton{ public static readonly MySigleton Instance = new MySingleton()}
namespace ConsoleApplication5{ class Singleton<T> where T : new() { private static readonly T inst = new T(); public static T Instance { get { return inst; } } }}and then use that simply by doing something like Singleton<MyClass>.Instance
namespace ConsoleApplication5{ class Singleton<T> where T : new() { private static readonly T inst = new T(); public static T Instance { get { return inst; } } }}
Subscribe to RSS headline updates from: