Click here to Skip to main content
12,452,106 members (31,948 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

3.6K views
Posted

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

You may also be interested in...

Pro
Pro

Comments and Discussions

 
QuestionAll About Singleton Pattern Pin
Peace ON20-Jul-13 1:04
memberPeace ON20-Jul-13 1:04 
GeneralIf that's all you need, you might as well just make a static... Pin
PIEBALDconsult8-Nov-11 17:30
memberPIEBALDconsult8-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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160826.1 | Last Updated 8 Nov 2011
Article Copyright 2011 by jamesklett
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid