一片模糊不懂
class singleton
{
    private static singleton _singleton;
    private static object obj = new object();
    private singleton()
    {
    }
    public static singleton getSingleton()
    {
        if (_singleton == null)
        {
            lock (obj)
            {
                if (_singleton == null)
                {
                    _singleton = new singleton();
                }
            }
        }
        return _singleton;
    }
}
為什麼要這樣寫?
單例要求不能實例化能直接取得,多線程時也要保持唯一性
接著要理解單例,可以先從最簡單用法
public static readonly singleton Instance = new singleton();
使用static readonly達到唯一跟實體化跟不能clone
這樣不管誰使用Instance都可以"取到同一個物件"
接著來理解你的CODE
1.使用static,但是缺少了readonly所以可以被修改,滿足不了第三點需求
2.private + 不建立set方法 + 只建立getSingleton方法用來替代readonly-
2.1 為什麼要判斷兩次_singleton==null
因為lock在最外層,每一次呼叫方法都要鎖住Thread這成本太高了
所以只在_singleton=null的時候才去lock
2.2 obj物件單純用來lock確保只有當前執行緒執行該區段
2.3 為什麼裡面還要包一個null判斷
因為外層的if判斷,會有多線程被修改問題,所以才要在裡面多包一層