首页 > 开发 > 综合 > 正文

My Singleton in C#

2024-07-21 02:19:38
字体:
来源:转载
供稿:网友
//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){}
}
};


商业源码热门下载www.html.org.cn

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表