Singleton Class – Basic Example

Below is an example of a Singleton implementation C# class.

public sealed class StaticData
{
    private  StaticData() {}
    public static readonly StaticData Instance = new StaticData();
    string connectionString = "";
    public string ConnectionToUse
    {
        get
        {
            if (connectionString.Length == 0)
            {
                connectionString = System.Configuration.ConfigurationManager.AppSettings.Get("DBConnection").ToString();
            }
            return connectionString;
        }
    }
}