html5中文学习网

您的位置: 首页 > 网络编程 > ASP.NET » 正文

My Singleton in C#_.NET教程_编程技术

[ ] 已经帮助:人解决问题
//MySingleton
using System;
//SingletonPage Class
class SingletonPage
{
//Fields
protected static SingletonPage checkoutpage;


//Constructor is protected to ensure Singleton
protected SingletonPage()
{
Console.WriteLine("if you see this line,then the only one instence is created!");
}

//Use this to Create SingletonPage instance
public static SingletonPage NewCheckOutPage()
{
if (checkoutpage==null)
checkoutpage= new SingletonPage();
return checkoutpage;
}

};
//-------------------------------------End of SingletonPage Class


//TestApp
class TestApp
{
public static void Main(string[] args)
{
Console.WriteLine("'create' pagea:");
SingletonPage pagea=SingletonPage.NewCheckOutPage();

Console.WriteLine("'create' pageb:");
SingletonPage pageb=SingletonPage.NewCheckOutPage();

Console.WriteLine("'create' pagec:");
SingletonPage pagec=SingletonPage.NewCheckOutPage();

Console.WriteLine("'create' paged:");
SingletonPage paged=SingletonPage.NewCheckOutPage();

while(true){}
}
};


CG2HTML5中文学习网 - HTML5先行者学习网
CG2HTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助