Skip to content

Instantly share code, notes, and snippets.

@p3nGu1nZz
Created March 1, 2024 18:23
Show Gist options
  • Save p3nGu1nZz/28fa2f5dd0d5659f7e0e106ed04a79cf to your computer and use it in GitHub Desktop.
Save p3nGu1nZz/28fa2f5dd0d5659f7e0e106ed04a79cf to your computer and use it in GitHub Desktop.
using System;
public class Singleton<T> where T : class, new()
{
// The single instance of the type T
private static readonly Lazy<T> instance = new(() => new T());
// The private constructor to prevent outside instantiation
public Singleton() { }
// The public property to get the instance of the type T
public static T Instance
{
get { return instance.Value; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment