My Singleton in C#
2004-08-04 20:54
399 查看
//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){}
}
};
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){}
}
};
相关文章推荐
- My Singleton in C#
- Implementing the Singleton Pattern in C#
- Implementing Singleton in C#
- Implementing the Singleton Pattern in C#
- My Prototype in C#
- Implementing the Singleton Pattern in C#
- 【转】单体模式-经典实现 Implementing the Singleton Pattern in C#
- My Adapter in C#
- My Prototype in C#
- Implementing the Singleton Pattern in C#
- Implementing the Singleton Pattern in C#
- Implementing the Singleton Pattern in C#
- Implementing the Singleton Pattern in C#
- Implementing the Singleton Pattern in C#[转载]
- My AbstractFactory in C#
- Singleton Pattern in C# 5种实现
- [C#] [C# in Depth] Implementing the Singleton Pattern in C#
- try install C# 2.0 sdk in my Computer !
- Singleton in C#
- My FactoryMethod in C#