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;
}

More from Design Patterns in C#

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details