The Definitive C# Singleton

It’s looks like it’s not thread safe but the framework actually guarantees that it is.

// .NET Singleton
sealed class Singleton
    static Singleton() {} // required to make lazy
    private Singleton() {}
    public static readonly Singleton Instance = new Singleton();

There’s also an interesting discussion of double locks in the article. Check out Exploring the Singleton Design Pattern for details.

← newer older →
.Net, Technology, Life, Whatever

Recent Posts

VSColorOutput for VS 2017 Released
Quick ReSharper tip for inline templates
NoSQL vs. NewSQL: What's the Difference?
Exploring Mithril, A JavaScript Framework for Building Brilliant Applications
Tweetz 1.1
Tweetz Desktop 1.0
Tweetz 0.11 Released
More... (1073)

Donate with PayPal