C# Singleton单例模式

 public class Singleton<T> where T : new()
    {
        private static object _locker = new object();
        private static T _instance;

        public static T Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (_locker)
                    {
                        if (_instance == null)
                        {
                            _instance = new T();
                        }
                    }
                }
                return _instance;
            }
        }
    }
posted @ 2014-11-18 11:40  邹邹  Views(193)  Comments(0)    收藏  举报