Static Constructor & Singleton class

后端 未结 2 1204
执念已碎
执念已碎 2021-02-05 06:23

I have an object cache which implements the Singleton design pattern. My approach to singleton was always to lazy load the static instance when the property is first accessed. <

2条回答
  •  情话喂你
    2021-02-05 07:25

    Rather than rolling your own threadsafe lazy initializer and possibly getting it wrong, I recommend reading the msdn on Lazy.

    https://docs.microsoft.com/en-us/dotnet/framework/performance/lazy-initialization#thread-safe-initialization

提交回复
热议问题