My Singleton in C#-.Net技术-3P代码网
繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> Asp.Net开发 >> My Singleton in C#

My Singleton in C#

2007-09-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介://MySingleton using System; //SingletonPage Class class SingletonPage { //Fields protected static SingletonPage checkoutpage; //Constructor is protected to ensure Singleton protected SingletonPage...
关键字:C# Singleton in My

//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){}

}

};

责任编辑:admin
相关文章