单例(Singleton)模式--C#模式
程序举例
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Singleton : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Singletons single1 = Singletons.Instance();
Singletons single2 = Singletons.Instance();
if (single1 == single2)
{
Response.Write("The same Instance");
}
}
}
public class Singletons
{
private static Singletons instance;
protected Singletons()
{
}
{
if (instance == null)
{
instance = new Singletons();
}
return instance;
}
}