You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

28 lines
611 B

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace HBLConsole.Service
  5. {
  6. /// <summary>
  7. /// 单例对象基类
  8. /// </summary>
  9. /// <typeparam name="T"></typeparam>
  10. public class Singleton<T> where T : new()
  11. {
  12. private static object _async = new object();
  13. private static T _instance;
  14. static readonly Lazy<T> instance = new Lazy<T>();
  15. /// <summary>
  16. /// 获取实例
  17. /// </summary>
  18. /// <returns></returns>
  19. public static T GetInstance()
  20. {
  21. return instance.Value;
  22. }
  23. }
  24. }