65.9K
CodeProject is changing. Read more.
Home

Simple Singleton Pattern in C#

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.83/5 (20 votes)

Jul 8, 2011

CPOL
viewsIcon

34944

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