Mike-Ward.Net

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

Tweetz 1.3.2
Tweetz 1.3 Release
Mithril Rising
Tweetz Release 1.2.4 - Screen Off Detection
Tweetz Desktop Support for 280 Characters
Quick Tip - Clear ReSharper's Cache to Fix False Errors
Quick Tip - Refined GitHub
More... (1082)

Donate