标签:style blog http color art re
private static Singleton instance; public Singleton() { //private 不让客户端 new } public static Singleton GetInstance() { if (instance == null) { instance = new Singleton(); } return instance; }
客户端
protected void Page_Load(object sender, EventArgs e) { Singleton s1 = Singleton.GetInstance(); Singleton s2 = Singleton.GetInstance(); if (s1 == s2) { Response.Write("我们是同一个<br>"); } Singleton s3 = new Singleton(); Singleton s4 = new Singleton(); if (s3 != s4) { Response.Write("我们不是同一个实例"); } }
比较简单,作个笔记.
http://blog.csdn.net/likika2012/article/details/11483167(应用场景)
标签:style blog http color art re
原文地址:http://www.cnblogs.com/sportdog/p/3848971.html