1
我想收集更多的變體來創建單例類。 您能否以您的意見在C#中提供給我最好的創作方式?C中的單例#
謝謝。
public sealed class Singleton
{
Singleton _instance = null;
public Singleton Instance
{
get
{
if(_instance == null)
_instance = new Singleton();
return _instance;
}
}
// Default private constructor so only we can instanctiate
private Singleton() { }
// Default private static constructor
private static Singleton() { }
}
Mmh的......聽起來像是已經要求.. – digEmAll 2011-02-18 12:01:02
@Klaus:這個實現是* not *罰款......屬性和字段是非靜態的......你怎麼能創建一個實例? – 2011-02-18 12:03:21
@Jon,對,「實例」應該是靜態的。沒有注意到。將編輯我的帖子。 – 2011-02-18 12:07:12