Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Simple Singleton Pattern in C#

, 8 Nov 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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:

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)

Share

About the Author

jamesklett
Software Developer (Senior)
Unknown
No Biography provided

Comments and Discussions

 
QuestionAll About Singleton Pattern PinmemberPeace ON20-Jul-13 1:04 
GeneralIf that's all you need, you might as well just make a static... PinmemberPIEBALDconsult8-Nov-11 17:30 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 8 Nov 2011
Article Copyright 2011 by jamesklett
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid