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

Checklist Buddy Available for Testing
Tweetz 2.0.0 Released
Tweetz 2.0 Beta
VSColorOutput 2.7 - Time Stamps
Fixed Focal-Length Eyeglasses, a Programmer's Best Friend
How to Choose the Right VPN Service
Two Handy Command Line Scripts
More... (1089)

Donate