位置于:书籍教程首页>>编程开发>>Asp.net教程>>正文

My Singleton in C#

http://www.xp163.com/制作:

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


中国.Net俱乐部转载此文。让我们一起进步,共享人类技术资源。[www.chinaaspx.com]


 最新网站更新
 网站My Singleton in C#说明

 

 书籍教程站内推荐信息
 书籍教程网站地图