.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;
}
}
}


1 Comments:

  • Heya neato was just blogging and saw your blog and thought it was nice so I should drop in and say Heya neato. Anyways I would be interested in exchanging links if you are up for it.

    By Anonymous Apropos, at 3:01 pm  

Post a Comment

Links to this post:

Create a Link

<< Home