Click here to Skip to main content
Click here to Skip to main content

Simple Singleton Pattern in C#

By , 8 Jul 2011
 

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)

About the Author

schamese
Software Developer
Germany Germany
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 2memberAkhil_Mittal26 Feb '13 - 22:54 
GeneralMy vote of 2memberOleksandr Kulchytskyi29 Dec '12 - 3:19 
GeneralReason for my vote of 2 This alternative is not 'lazyloading...memberKabwla.Phone1 Nov '11 - 3:02 
GeneralRe: Reason for my vote of 2This alternative is not 'lazyloading... [modified]memberIan A Davidson10 Apr '13 - 15:19 
GeneralAn exception thrown inside Singletin's .ctor will be thrown ...memberKelqualyn31 Oct '11 - 20:44 
GeneralRe: An exception thrown inside Singletin's .ctor will be thrown ...memberIan A Davidson10 Apr '13 - 15:33 
GeneralRe: An exception thrown inside Singletin's .ctor will be thrown ...memberKelqualyn11 Apr '13 - 1:27 
GeneralRe: An exception thrown inside Singletin's .ctor will be thrown ...memberIan A Davidson11 Apr '13 - 2:04 
GeneralReason for my vote of 5 the simplest and because of it the b...memberRobert Krzysztof Winkler31 Oct '11 - 2:03 
GeneralRe: Reason for my vote of 5the simplest and because of it the b...memberIan A Davidson10 Apr '13 - 14:37 
GeneralThe field should probably be private.memberRichard Deeming13 Jul '11 - 8:11 

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130513.1 | Last Updated 8 Jul 2011
Article Copyright 2011 by schamese
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid