Cached property vs Lazy

后端 未结 7 1305

In .NET 4 the following snippet with a cached property can also be written using the System.Lazy class. I measured the performance of both approaches and it\'s pret

相关标签:
7条回答
  • 2020-12-04 13:58

    Use Lazy<T>, as it expresses exactly what you are doing - lazy loading.

    In addition, it keeps your property very clean and is thread safe.

    0 讨论(0)
提交回复
热议问题