Blog Home  Home Feed your aggregator (RSS 2.0)  
kevin Mocha - Singleton
Bookmarks collected from web.
 
 Monday, July 23, 2007

Implementing the Singleton Pattern in C#


http://www.yoda.arachsys.com/csharp/singleton.html

Five implementations are given. The author also compared their pros and cons.

Bestone is:
public sealed class Singleton
{
Singleton()
{
}

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

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

internal static readonly Singleton instance = new Singleton();
}
}

Monday, July 23, 2007 3:49:45 PM UTC  #    Comments [0]    |  Trackback
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Copyright © 2008 Kevin Mocha. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: