design-patterns/Singleton/LazySingleton.cs

15 lines
381 B
C#
Raw Permalink Normal View History

2023-09-04 10:29:51 +00:00
public sealed class LazySingleton
{
private LazySingleton() { }
private static readonly Lazy<LazySingleton> _lazy = new Lazy<LazySingleton>(() => new LazySingleton());
public static LazySingleton GetInstance(string value)
{
var instance = _lazy.Value;
instance.Value = value;
return instance;
}
public string Value { get; set; }
}