.comment-link {margin-left:.6em;}

Ben Cops

Tuesday, February 08, 2005

Implementing the Singleton Pattern in C#

Implementing the Singleton Pattern in C#

For reference, I always use the fourth version:


public sealed class Singleton
{
static readonly Singleton instance=new Singleton();

// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit
static Singleton()
{
}

Singleton()
{
}

public static Singleton Instance
{
get
{
return instance;
}
}
}


0 Comments:

Post a Comment

<< Home