Mid
From PDF
GoF Patterns
Gang of Four Patterns
Thread-Safe Singleton (Eager Initialization):?
- The singleton instance is created when the class is loaded, guaranteeing
thread safety without locking. However, it may have a slight performance
overhead due to the instance being created regardless of whether it is
needed.
public class Singleton
{
private static readonly Singleton _instance = new Singleton();
private Singleton() { }
public static Singleton Instance => _instance;
}Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png