Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Simple Singleton Pattern in C#

3.83/5 (20 votes)
8 Jul 2011CPOL 34.9K  
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:


C#
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)