1:對象在類內部實例化且僅一次
2:構造函數私有
3:用屬性get將對象讀出來,如果為空那么實例化一次如:
public class Singleton
{
static Singleton instance = null;
private Singleton()
{
}
public static Singleton Instance
{
get
{
if (instance == null)
{
instance = new Singleton();
}
return instance;
}
}
}
posted on 2008-09-08 16:58
天書 閱讀(90)
評論(0) 編輯 收藏 引用