Created
March 1, 2024 18:23
-
-
Save p3nGu1nZz/28fa2f5dd0d5659f7e0e106ed04a79cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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