1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
using System; public class Singleton<T> where T : class, new() { private static T _instance; public static T Instance { get { if (_instance == null) _instance = Activator.CreateInstance<T>(); return _instance; } } }