My Singleton in C#

王朝c#·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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

}

};

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航