Lazy:
public sealed class Singleton { private static readonly Lazy<Singleton> lazy = new Lazy<Singleton> (() => new Singleton()); public static Singleton Instance { get { return lazy.Value; } } private Singleton() { } }
Form:
private static FrmConfig _defaultInstance;
public static FrmConfig Instance
{
get
{
if (_defaultInstance == null || _defaultInstance.IsDisposed)
{
_defaultInstance = new FrmConfig();
}
return _defaultInstance;
}
set => _defaultInstance = value;
}