Singleton Pattern : Singleton Pattern « Design Patterns « C# / CSharp Tutorial






using System;

public class SingletonClass
{
    private static SingletonClass instance;

    static SingletonClass()
    {
        instance = new SingletonClass();
    }

    private SingletonClass() { }

    public static SingletonClass Instance
    {
        get { return instance; }
    }

    public void SomeMethod1() { }
    public void SomeMethod2() { }
}

public class MainClass
{
    public static void Main()
    {
        SingletonClass s = SingletonClass.Instance;
        s.SomeMethod1();

        SingletonClass.Instance.SomeMethod2();

    }
}








28.1.Singleton Pattern
28.1.1.Singleton Pattern
28.1.2.Singleton Pattern 2