Click here to Skip to main content
11,437,816 members (49,913 online)
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

 
GeneralAn exception thrown inside Singletin's .ctor will be thrown ... Pin
Kelqualyn31-Oct-11 21:44
memberKelqualyn31-Oct-11 21:44 
GeneralRe: An exception thrown inside Singletin's .ctor will be thrown ... Pin
Ian A Davidson10-Apr-13 16:33
memberIan A Davidson10-Apr-13 16:33 
GeneralRe: An exception thrown inside Singletin's .ctor will be thrown ... Pin
Kelqualyn11-Apr-13 2:27
memberKelqualyn11-Apr-13 2:27 
GeneralRe: An exception thrown inside Singletin's .ctor will be thrown ... Pin
Ian A Davidson11-Apr-13 3:04
memberIan A Davidson11-Apr-13 3:04 

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