Posts

Showing posts from April, 2012

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 public class Singleton where T : class, new() { private Singleton() {} private static readonly Lazy instance = new Lazy (() => new T()); public static T Instance { get { return instance.Value; } } }