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

Simple Singleton Pattern in C#

By , 27 Oct 2011
Rate this:
Please Sign up or sign in to vote.
Another alternative:

class Singleton 
    public static Singleton m_Instance;
    //Prevent instance creation from other classes
    private Singleton() { }
    public static Singleton Instance 
       get { return m_Instance ?? (m_Instance = new Singleton()); } 
Could you comment pros and cons with alternative-3?


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

About the Author


Peru Peru
No Biography provided

Comments and Discussions

GeneralMy vote of 4 PinmemberPeace ON20-Jul-13 0:33 
GeneralReason for my vote of 1 I'm a big fan of alternative 8, that... PinmemberKabwla.Phone6-Nov-11 21:27 
GeneralWhile Alternative 4 will only load the instance when it is c... PinmemberAndrew Rissing27-Oct-11 5:23 

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.140415.2 | Last Updated 27 Oct 2011
Article Copyright 2011 by ForgaSw
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid