public class SingleModelwhere 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 .Instance.Name; //string Name2 = SingleTon.SingleModel .Instance.Name; //string Name3 = SingleTon.SingleModel .Instance.Name; }
不想寫了,就貼一段代碼吧
專注于為中小企業(yè)提供網(wǎng)站設(shè)計(jì)制作、做網(wǎng)站服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)巫溪免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了成百上千企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。