A generic singleton using Lazy< T >

Carring on from the generic singleton post here.

Since we have .NET 4, we can now make use of Lazy< T >

public class Singleton< T > where T : class, new()
{
    private Singleton() {}

    private static readonly Lazy< T > instance = new Lazy< T >(() => new T());

    public static T Instance { get { return instance.Value; } } 
}

Popular posts from this blog

Execution of user code in the .NET Framework is disabled

Service Broker sys.transmission_queue clean up

What do I use to write software?