11,570 questions
Here is how to use a private constructor.
public sealed class Singleton
{
private static readonly Lazy<Singleton> Lazy = new(() => new Singleton());
public static Singleton Instance => Lazy.Value;
public DateTime DateTime { get; set; }
private Singleton()
{
DateTime = DateTime.Now;
}
}
Then to call Singleton.Instance.DateTime
the constructor is only called the first time.