DEV Community

Basit Jamil
Basit Jamil

Posted on

Singleton design pattern eager initialization in C#

// Code
public class SingletonDesignPattern
{
    private static SingletonDesignPattern instance = new SingletonDesignPattern();
    private SingletonDesignPattern() { }
    public static SingletonDesignPattern GetInstance
    {
        get { return instance; } //can only be get no set
    }
}

// Usage
SingletonDesignPattern singleton = 
SingletonDesignPattern.GetInstance;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)