Click here to Skip to main content
15,887,776 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

Simple Singleton Pattern in C#

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
8 Nov 2011CPOL 7.6K   1
You should do it like this:public sealed class MySingleton { public static readonly MySingleton SharedInstance = new MySingleton (); private MySingleton () : base() { }}

You should do it like this:


C#
public sealed class MySingleton 
{
    
    public static readonly MySingleton SharedInstance = new MySingleton ();

    private MySingleton () : base()
    {
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Unknown
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralIf that's all you need, you might as well just make a static... Pin
PIEBALDconsult8-Nov-11 17:30
mvePIEBALDconsult8-Nov-11 17:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.