Singleton 泛型实例

来源:互联网 发布:电子邮件软件哪个好 编辑:程序博客网 时间:2024/05/29 11:37

抽象单类模式

public abstract class Singleton<T>  where T : new(){        private static T instance;        private static readonly object loca = new object();        public static T Instance        {            get            {                if (instance == null)                {                    lock (loca)                    {                        if (instance == null)                        {                            instance = new T();                        }                    }                }                return instance;            }        }}