Singleton Design Pattern

Save up to 45% on Add-ons for Xbox games!

Singleton design pattern makes sure that there should be only one instance of the specific class at a given time. Please refer below example code for C# implementation.

Example

// Singleton class Customer
public class Customer
{
    private static readonly Lazy<Customer> _lazy = new Lazy<Customer>(() => new Customer());

    private Customer() { }

    public static Customer Instance
    {
        get
        {
            return _lazy.Value;
        }
    }
}
Written on August 10, 2019

Xbox Games - Gears 5