public class SingleModel<T> where T : class,new() { private static T _instance; private static readonly Object _lock = new Object(); public static T Instance { get { if (_instance == null) { lock (_lock) { if (_instance == null) { _instance = new T(); } } } return _instance; } } //string Name1 = SingleTon.SingleModel<Test>.Instance.Name; //string Name2 = SingleTon.SingleModel<Test1>.Instance.Name; //string Name3 = SingleTon.SingleModel<Test2>.Instance.Name; }
不想写了,就贴一段代码吧
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。