当前位置: 首页 > 图文教程 > .Net技术 > C# > My Singleton in C#

C#
C#.Net网络程序开发-Socket篇
My Singleton in C#
My Prototype in C#
My FactoryMethod in C#
C# 编码规范和编程好习惯
C#数据库操作的三种经典用法
C#实现24点算法源代码
C#中使用GDI 让网站新闻标题个性化
Java util.concurrent中LockSupport类在C#中的实现
如何使用C#进行Visio二次开发
论C#变得越来越臃肿是不可避免的
C-Sharp开发应避免的几个小滥用
C#实现类似qq的屏幕截图程序
C#关闭电脑
用C#画树
C#从视频截图的方法
把new、virtual、override说透
关于enum应用的总结
C#修饰符总结
c#定位CUP所有问题

My Singleton in C#


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 64 ::
收藏到网摘: n/a

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