Is Lazy<T> a good solution for a thread safe lazy loaded singleton?
问题 We implemented a lazy loaded singleton using double locking on get to make sure the instance is only initialized once (and not twice due to thread race conditions). I was wondering if simply using Lazy<T> is a good solution for this problem? I.E. private static Lazy<MyClass> _instance = new Lazy<MyClass>(() => return new MyClass()); public static MyClass Instance { get { return _instance.Value; } } 回答1: I suggest you to read referencede articles from comments: Lazy Class Implementing the