Singleton
by Noffer on Nov.08, 2011, under Software Development
Saw a new twist on the Singleton pattern. Here it is…
class ThreadSafeSingleton
{
// typical pattern: private constructor and property to return the instance
private ThreadSafeSingleton() { }
public static ThreadSafeSingleton Instance
{
get { return Nested.instance; }
}
// using this pattern helps make a simple, fast thread-safe singleton that doesn't use a lock
private class Nested
{
static Nested() { }
internal static readonly ThreadSafeSingleton instance = new ThreadSafeSingleton();
}
}
November 26th, 2011 on 11:51 AM
God, I feel like I shulod be takin notes! Great work