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 Jul 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
This should do it as well:class Singleton { public static readonly Singleton m_Instance = new Singleton(); // Prevent instance creation from other classes private Singleton() { } public static Singleton Instance { get { return m_Instance; } }}And it is "Singleton",...

This should do it as well:

class Singleton {
    public static readonly Singleton m_Instance = new Singleton();
 
    // Prevent instance creation from other classes
    private Singleton() { }
 
    public static Singleton Instance { get { return m_Instance; } }
}

And it is "Singleton", not a "single Ton"... SCNR

License

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

Share

About the Author

schamese
Software Developer
Germany Germany
No Biography provided

Comments and Discussions

 
SuggestionSingleton Pattern Example PinmemberDeveloper Hemu Patel8-Aug-14 4:10 
GeneralMy vote of 2 PinmemberBartlomiej Filipek6-Oct-13 23:31 
GeneralMy vote of 4 PinmemberPeace ON20-Jul-13 0:32 
GeneralMy vote of 2 PinmemberAkhil_Mittal26-Feb-13 22:54 
GeneralMy vote of 2 PinmemberOleksandr Kulchytskyi29-Dec-12 3:19 
GeneralReason for my vote of 2 This alternative is not 'lazyloading... PinmemberKabwla.Phone1-Nov-11 3:02 
GeneralRe: Reason for my vote of 2This alternative is not 'lazyloading... [modified] PinmemberIan A Davidson10-Apr-13 15:19 
GeneralAn exception thrown inside Singletin's .ctor will be thrown ... PinmemberKelqualyn31-Oct-11 20:44 
GeneralRe: An exception thrown inside Singletin's .ctor will be thrown ... PinmemberIan A Davidson10-Apr-13 15:33 
GeneralRe: An exception thrown inside Singletin's .ctor will be thrown ... PinmemberKelqualyn11-Apr-13 1:27 
GeneralRe: An exception thrown inside Singletin's .ctor will be thrown ... PinmemberIan A Davidson11-Apr-13 2:04 
GeneralReason for my vote of 5 the simplest and because of it the b... PinmemberRobert Krzysztof Winkler31-Oct-11 2:03 
GeneralRe: Reason for my vote of 5the simplest and because of it the b... PinmemberIan A Davidson10-Apr-13 14:37 
GeneralThe field should probably be private. PinmemberRichard Deeming13-Jul-11 8:11 

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
Web02 | 2.8.141022.2 | Last Updated 8 Jul 2011
Article Copyright 2011 by schamese
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid