您可以在这里快速查找:


 
您的位置: 编程学习 > asp.net教程 > 200509
文章分类

Java技术
2005: 03 04 05 06 07 08
09 10 11 12
2006: 01 02

Asp.net
2005: 07 08 09 10 11 12
2006: 01 02

VB编程
2006: 02

Asp编程
2005: 11 12
2006: 01 02

C++/VC
2005: 10 11 12
2006: 01 02

Delphi
2005: 12
2006: 01 02

其它

 本文章适合所有读者

My Singleton in C#

beautyispower

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