| 面向 | 欄位初始化 | 靜態建構函數 |
|---|---|---|
| 簡便性 | 最簡便 | 較簡便 |
| 安全性 | 較安全 | 最安全 |
| 例外處理 | 極難 | 容易 |
public class MySingleton {
private static readonly MySingleton _theOneAndOnly;
static MySingleton() { _theOneAndOnly = new MySingleton(); }
public static MySingleton TheOnly { get { return _theOneAndOnly; } }
private MySingleton() { }
}